add test for readdir
This commit is contained in:
parent
cbeab07352
commit
011b4bf8e7
@ -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
|
||||
|
5
test/readdir/Makefile
Normal file
5
test/readdir/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
include ../test_common.mk
|
||||
|
||||
EXTRA_C_FLAGS :=
|
||||
EXTRA_LINK_FLAGS :=
|
||||
BIN_ARGS :=
|
23
test/readdir/main.c
Normal file
23
test/readdir/main.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user