From 4ac5ffbb8314d307964f21a774e923a62a3c36e0 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 5 Feb 2018 09:31:32 +0100 Subject: fsclose01: Add tmpfile() test case Close #1971. --- testsuites/fstests/fsclose01/fsclose01.doc | 2 ++ testsuites/fstests/fsclose01/init.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'testsuites/fstests') diff --git a/testsuites/fstests/fsclose01/fsclose01.doc b/testsuites/fstests/fsclose01/fsclose01.doc index 29277a4a91..89a734a42c 100644 --- a/testsuites/fstests/fsclose01/fsclose01.doc +++ b/testsuites/fstests/fsclose01/fsclose01.doc @@ -17,6 +17,7 @@ directives: - lseek() - read() - readv() + - tmpfile() - write() - writev() @@ -24,3 +25,4 @@ concepts: - Ensure the close() return -1 with errno set to EBUSY in case the file descriptor is still in use. + - Ensure that close() cleans up resources allocated by tmpfile(). diff --git a/testsuites/fstests/fsclose01/init.c b/testsuites/fstests/fsclose01/init.c index 3b65b3b432..786749d2e2 100644 --- a/testsuites/fstests/fsclose01/init.c +++ b/testsuites/fstests/fsclose01/init.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2017 embedded brains GmbH. All rights reserved. + * Copyright (c) 2012, 2018 embedded brains GmbH. All rights reserved. * * embedded brains GmbH * Dornierstr. 4 @@ -426,7 +426,7 @@ static void test_fd_free_fifo(const char *path) rtems_test_assert(a != b); } -static void test(test_context *ctx) +static void test_close(test_context *ctx) { const char *path = "generic"; int rv; @@ -507,10 +507,33 @@ static void test(test_context *ctx) rtems_test_assert(ctx->writev_count == 1); } +static void test_tmpfile(test_context *ctx) +{ + rtems_resource_snapshot before; + FILE *f; + int rv; + + rv = mkdir("/tmp", S_IRWXU | S_IRWXG | S_IRWXO); + rtems_test_assert(rv == 0); + + f = tmpfile(); + rtems_test_assert(f != NULL); + rv = fclose(f); + rtems_test_assert(rv == 0); + + rtems_resource_snapshot_take(&before); + f = tmpfile(); + rtems_test_assert(f != NULL); + rv = fclose(f); + rtems_test_assert(rv == 0); + rtems_test_assert(rtems_resource_snapshot_check(&before)); +} + static void Init(rtems_task_argument arg) { TEST_BEGIN(); - test(&test_instance); + test_close(&test_instance); + test_tmpfile(&test_instance); TEST_END(); rtems_test_exit(0); } -- cgit v1.2.3