From 011b4bf8e792df32668c0c204fb4492a2c09a699 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Wed, 13 Mar 2019 17:32:35 +0800 Subject: [PATCH] add test for readdir --- test/Makefile | 4 ++-- test/readdir/Makefile | 5 +++++ test/readdir/main.c | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/readdir/Makefile create mode 100644 test/readdir/main.c diff --git a/test/Makefile b/test/Makefile index c35b0630..5075bddb 100644 --- a/test/Makefile +++ b/test/Makefile @@ -4,7 +4,7 @@ PROJECT_DIR := $(realpath $(CUR_DIR)/../) # Dependencies: need to be compiled but not to run by any Makefile target TEST_DEPS := dev_null # Tests: need to be compiled and run by test-% target -TESTS := empty argv hello_world malloc file getpid spawn pipe time truncate +TESTS := empty argv hello_world malloc file getpid spawn pipe time truncate readdir # Benchmarks: need to be compiled and run by bench-% target BENCHES := spawn_and_exit_latency pipe_throughput @@ -13,7 +13,7 @@ BUILD_TARGETS := $(TEST_DEPS) $(TESTS) $(BENCHES) TEST_TARGETS := $(TESTS:%=test-%) BENCH_TARGETS := $(BENCHES:%=bench-%) CLEAN_TARGETS := $(BUILD_TARGETS:%=clean-%) -.PHONY: all build test clean $(BUILD_TARGETS) $(TEST_TARGETS) $(BENCH_TARGETS) $(CLEAN_TARGETS) +.PHONY: all build test clean sefs $(BUILD_TARGETS) $(TEST_TARGETS) $(BENCH_TARGETS) $(CLEAN_TARGETS) # Use echo program instead of built-in echo command in shell. This ensures # that echo can recognize escaped sequences (with -e argument) regardless of diff --git a/test/readdir/Makefile b/test/readdir/Makefile new file mode 100644 index 00000000..9e1b6dec --- /dev/null +++ b/test/readdir/Makefile @@ -0,0 +1,5 @@ +include ../test_common.mk + +EXTRA_C_FLAGS := +EXTRA_LINK_FLAGS := +BIN_ARGS := diff --git a/test/readdir/main.c b/test/readdir/main.c new file mode 100644 index 00000000..26b8f46c --- /dev/null +++ b/test/readdir/main.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) { + DIR* dirp = opendir("."); + if (dirp == NULL) { + printf("failed to open directory at /\n"); + return -1; + } + + struct dirent *dp; + while ((dp = readdir(dirp)) != NULL) { + printf("get: %s\n", dp->d_name); + } + + closedir(dirp); + + printf("Read directory test successful\n"); + return 0; +}