diff --git a/fs_mark/Makefile b/fs_mark/Makefile new file mode 100644 index 000000000..f6f97c81a --- /dev/null +++ b/fs_mark/Makefile @@ -0,0 +1 @@ +$(eval $(call add_test, fs_mark)) diff --git a/fs_mark/fs_mark.c b/fs_mark/fs_mark.c new file mode 100644 index 000000000..6709e7056 --- /dev/null +++ b/fs_mark/fs_mark.c @@ -0,0 +1,77 @@ +/* + * Phoenix-RTOS + * + * Runs fs_mark program and does clean up right after. + * + * Copyright 2023 Phoenix Systems + * Author: Adam Debek + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#include +#include +#include +#include +#include +#include +#include + +int remove_dir_recursive(const char *const dirPath) +{ + DIR *const dir = opendir(dirPath); + if (dir) { + struct dirent *entry; + while ((entry = readdir(dir))) { + if (!strcmp(".", entry->d_name) || !strcmp("..", entry->d_name)) { + continue; + } + char filename[strlen(dirPath) + strlen(entry->d_name) + 2]; + sprintf(filename, "%s/%s", dirPath, entry->d_name); + int (*const remove_func)(const char *) = entry->d_type == dtDir ? remove_dir_recursive : remove; + if (remove_func(entry->d_name)) { + closedir(dir); + return -1; + } + } + if (closedir(dir)) { + return -1; + } + } + return remove(dirPath); +} + +int main(int argc, char **argv) +{ + const char *const fs_mark_path = "/usr/bin/fs_mark"; + char cmd[128]; + char dirPath[128]; + int i; + + fprintf(stderr, "siemka xddddddddddddddd\n"); + + strcpy(dirPath, argv[2]); + strcpy(cmd, fs_mark_path); + + for (i = 1; i < argc; i++) { + strcat(cmd, " "); + strcat(cmd, argv[i]); + } + + fprintf(stderr, "siemka xddddddddddddddd\n"); + + if (system(cmd) < 0) { + fprintf(stderr, "Error in system()\n"); + return 1; + } + + /* Clean test directory */ + if (remove_dir_recursive(dirPath) < 0) { + fprintf(stderr, "Error in remove_dir_recursive()\n"); + return 1; + } + + return 0; +} diff --git a/fs_mark/fs_mark.py b/fs_mark/fs_mark.py new file mode 100644 index 000000000..9ab5aff09 --- /dev/null +++ b/fs_mark/fs_mark.py @@ -0,0 +1,79 @@ +import trunner +import timing_data as t_data + +from trunner.ctx import TestContext +from trunner.dut import Dut +from trunner.types import TestResult, Result, Status + + +def harness(dut: Dut, ctx: TestContext): + results = [] + test_name = None + f_use = None + count = None + size = None + files_sec = None + app_overhead = None + result = None + target = trunner.ctx.target.name + + NAME = r"(.+?)/bin/(?Pfs_mark.+?)\r+\n" + MSG_LINE = r"(\s+)(?P([\d\.]+\s+){23})\r+\n" + FINAL = r"(?PInsufficient free space.+?)\r+\n" + END = r"(?PAverage Files/sec:.+?)\r+\n" + + while True: + idx = dut.expect([ + NAME, + MSG_LINE, + FINAL, + END + ], timeout=50) + parsed = dut.match.groupdict() + + if idx == 0: + test_name = parsed["name"] + elif idx == 1: + splited_line = parsed["line"].split() + f_use = splited_line[0] + count = splited_line[1] + size = splited_line[2] + files_sec = splited_line[3] + app_overhead = splited_line[4] + + dict = {} + dict['creatMin'] = splited_line[5] + dict['creatAvg'] = splited_line[6] + dict['creatMax'] = splited_line[7] + dict['writeMin'] = splited_line[8] + dict['writeAvg'] = splited_line[9] + dict['writeMax'] = splited_line[10] + dict['closeMin'] = splited_line[17] + dict['closeAvg'] = splited_line[18] + dict['closeMax'] = splited_line[19] + + result = Result(name=str(test_name), status=Status.OK) + + for name, value in dict.items(): + if not t_data.timing_dict[(target, name)][0] <= int(value) <= t_data.timing_dict[(target, name)][1]: + result.status = Status.FAIL + result.msg += "\n\t" + name + " exec time - " + value + \ + " out of range [" + str(t_data.timing_dict[(target, name)][0]) + \ + " - " + str(t_data.timing_dict[(target, name)][1]) + "]" + + if result.status == Status.FAIL: + result.msg += "\n\n\tF_Use%: " + str(f_use) + result.msg += "\n\tCount: " + str(count) + result.msg += "\n\tSize: " + str(size) + result.msg += "\n\tFiles/sec: " + str(files_sec) + result.msg += "\n\tApp overhead: " + str(app_overhead) + "\n\n" + + if result.status == Status.FAIL: + results.append(result) + break + + elif idx == 2 or idx == 3: + results.append(result) + break + + return TestResult(msg=Result.format_output(results, ctx), status=result.status) diff --git a/fs_mark/test.yaml b/fs_mark/test.yaml new file mode 100644 index 000000000..e57966037 --- /dev/null +++ b/fs_mark/test.yaml @@ -0,0 +1,12 @@ +test: + type: harness + harness: fs_mark.py + nightly: true + + tests: + - name: test1 + execute: fs_mark -d /tmp/1 -s 1000 -n 500 -v -k + # - name: test2 + # execute: fs_mark -d /tmp/2 -s 1000 -n 500 -v + # - name: test3 + # execute: fs_mark -d /tmp/3 -s 100 -n 5000 -v diff --git a/fs_mark/timing_data.py b/fs_mark/timing_data.py new file mode 100644 index 000000000..c05e98f9d --- /dev/null +++ b/fs_mark/timing_data.py @@ -0,0 +1,22 @@ +# Timing ranges used in fs_mark harness + +timing_dict = { + ('ia32-generic-qemu', 'creatMin'): (0, 90000), + ('ia32-generic-qemu', 'creatAvg'): (0, 90000), + ('ia32-generic-qemu', 'creatMax'): (0, 90000), + ('ia32-generic-qemu', 'writeMin'): (0, 90000), + ('ia32-generic-qemu', 'writeAvg'): (0, 90000), + ('ia32-generic-qemu', 'writeMax'): (0, 90000), + ('ia32-generic-qemu', 'closeMin'): (0, 90000), + ('ia32-generic-qemu', 'closeAvg'): (0, 90000), + ('ia32-generic-qemu', 'closeMax'): (0, 90000), + ('armv7a9-zynq7000-zturn', 'creatMin'): (), + ('armv7a9-zynq7000-zturn', 'creatAvg'): (), + ('armv7a9-zynq7000-zturn', 'creatMax'): (), + ('armv7a9-zynq7000-zturn', 'writeMin'): (), + ('armv7a9-zynq7000-zturn', 'writeAvg'): (), + ('armv7a9-zynq7000-zturn', 'writeMax'): (), + ('armv7a9-zynq7000-zturn', 'closeMin'): (), + ('armv7a9-zynq7000-zturn', 'closeAvg'): (), + ('armv7a9-zynq7000-zturn', 'closeMax'): () +} \ No newline at end of file