Sync kernel structures with upstream, update tests

This commit is contained in:
2023-09-01 22:57:11 +01:00
parent 085a7bdd4b
commit 1e46f84cf9
19 changed files with 170 additions and 101 deletions
+3 -3
View File
@@ -8,9 +8,9 @@ else
UMKA_SHELL ?= sudo taskset 1 ../umka_shell -c
endif
xfs_tests := $(addsuffix .out.log, $(basename $(wildcard *\#xfs_*.t)))
xfsv5_tests := $(addsuffix .out.log, $(basename $(wildcard *\#xfsv5_*.t)))
exfat_tests := $(addsuffix .out.log, $(basename $(wildcard *\#exfat_*.t)))
test_dirs := $(wildcard t???*)
test_logs := $(addsuffix .out.log, $(basename $(wildcard *\#xfsv5_*.t)))
test_run_ := $(addsuffix .out.log, $(basename $(wildcard *\#exfat_*.t)))
fat_tests := $(addsuffix .out.log, $(basename $(wildcard *\#fat_*.t)))
ext_tests := $(addsuffix .out.log, $(basename $(wildcard *\#ext_*.t)))
s05k_tests := $(addsuffix .out.log, $(basename $(wildcard *\#s05k_*.t)))
-303
View File
@@ -1,303 +0,0 @@
/*
SPDX-License-Identifier: GPL-2.0-or-later
UMKa - User-Mode KolibriOS developer tools
runtests - the test runner
Copyright (C) 2023 Ivan Baravy <dunkaist@gmail.com>
*/
#include <dirent.h>
#include <errno.h>
#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/types.h>
#include "optparse/optparse.h"
#ifndef PATH_MAX
#define PATH_MAX 0x1000
#endif
#define CMPFILE_BUF_LEN 0x100000
#define TIMEOUT_FILENAME "timeout.txt"
#define TIMEOUT_STR_MAX_LEN 16
#define ACTION_RUN 0
_Thread_local char bufa[CMPFILE_BUF_LEN];
_Thread_local char bufb[CMPFILE_BUF_LEN];
_Thread_local char timeoutfname[PATH_MAX];
_Thread_local char reffname[PATH_MAX];
_Thread_local char outfname[PATH_MAX];
int silent_success = 1;
static int
is_valid_test(const char *name) {
// Check that name starts with t\d\d\d
if (name[0] != 't') {
return 0;
}
for (size_t i = 1; i < 4 && name[i]; i++) {
if (name[1] < '0' || name[1] > '9') {
return 0;
}
}
// Check that run.us file exists
sprintf(reffname, "%s/%s", name, "run.us");
FILE *f = fopen(reffname, "rb");
if (f) {
fclose(f);
}
return f != NULL;
}
static int
cmpfiles(const char *fnamea, const char *fnameb) {
int result = 0;
FILE *filea = fopen(fnamea, "rb");
if (!filea) {
fprintf(stderr, "Can't open file '%s' for reading: %s\n", fnamea,
strerror(errno));
return -1;
}
FILE *fileb = fopen(fnameb, "rb");
if (!fileb) {
fprintf(stderr, "Can't open file '%s' for reading: %s\n", fnameb,
strerror(errno));
fclose(filea);
return -1;
}
while (1) {
size_t reada = fread(bufa, 1, CMPFILE_BUF_LEN, filea);
size_t readb = fread(bufb, 1, CMPFILE_BUF_LEN, fileb);
if (reada != readb || memcmp(bufa, bufb, reada)) {
fprintf(stderr, "[!] files %s and %s don't match\n", fnamea,
fnameb);
result = -1;
break;
}
if (feof(filea) && feof(fileb)) {
break;
}
}
fclose(filea);
fclose(fileb);
return result;
}
static int
check_test_artefacts(const char *testname) {
DIR *tdir = opendir(testname);
if (!tdir) {
fprintf(stderr, "Can't open directory '%s': %s\n", testname,
strerror(errno));
return -1;
}
struct dirent *dent;
while ((dent = readdir(tdir))) {
const char *refdot = strstr(dent->d_name, "ref.");
if (!refdot) {
continue;
}
size_t ref_off = refdot - dent->d_name;
sprintf(reffname, "%s/%s", testname, dent->d_name);
strcpy(outfname, reffname);
memcpy(outfname + strlen(testname) + 1 + ref_off, "out", 3);
if (cmpfiles(reffname, outfname)) {
return -1;
}
}
closedir(tdir);
return 0;
}
struct test_wait_arg {
int pid;
pthread_cond_t *cond;
};
static unsigned
get_test_timeout(const char *testname) {
sprintf(timeoutfname, "%s/%s", testname, TIMEOUT_FILENAME);
FILE *f = fopen(timeoutfname, "rb");
if (!f) {
fprintf(stderr, "[!] Can't open %s\n: %s\n", TIMEOUT_FILENAME,
strerror(errno));
return 0;
}
char str[TIMEOUT_STR_MAX_LEN];
fread(str, 1, TIMEOUT_STR_MAX_LEN, f);
fclose(f);
unsigned n, sec = 0, min = 0;
char *end;
n = strtoul(str, &end, 0);
switch (*end) {
case 's':
sec = n;
break;
case 'm':
min = n;
sec = strtoul(end+1, &end, 0);
break;
default:
fprintf(stderr, "[!] bad timeout value: %s\n", str);
return 0;
}
return min*60 + sec;
}
#ifndef _WIN32
#include <sys/wait.h>
static void *
thread_wait(void *arg) {
struct test_wait_arg *wa = arg;
int status;
waitpid(wa->pid, &status, 0);
pthread_cond_signal(wa->cond);
return (void *)(intptr_t)status;
}
static void *
run_test(const void *arg) {
const char *test_name = arg;
void *result = NULL;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&mutex);
int child;
if (!(child = fork())) {
chdir(test_name);
execl("../../umka_shell", "../../umka_shell", "-ri", "run.us", "-o",
"out.log", NULL);
fprintf(stderr, "Can't run test command: %s\n", strerror(errno));
return (void *)-1;
}
pthread_t t;
struct test_wait_arg wa = {.pid = child, .cond = &cond};
pthread_create(&t, NULL, thread_wait, &wa);
unsigned tout = get_test_timeout(test_name);
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += tout;
int status;
if ((status = pthread_cond_timedwait(&cond, &mutex, &ts))) {
fprintf(stderr, "[!] %s: timeout (%um%us)\n", test_name,
tout/60, tout % 60);
kill(child, SIGKILL);
result = (void *)(intptr_t)status;
}
pthread_join(t, &result);
pthread_mutex_unlock(&mutex);
return result;
}
#else
#include <errhandlingapi.h>
#include <intsafe.h>
#include <io.h>
#include <processthreadsapi.h>
#include <synchapi.h>
static void *
run_test(const void *arg) {
const char *test_name = arg;
void *result = NULL;
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
unsigned tout = get_test_timeout(test_name);
if(!CreateProcessA(NULL, "../umka_shell -ri run.us -o out.log", NULL,
NULL, FALSE, 0, NULL, test_name, &si, &pi)) {
fprintf(stderr, "CreateProcess failed: %lu\n", GetLastError());
return (void *)-1;
}
DWORD wait_res = WaitForSingleObject(pi.hProcess, tout*1000);
if (wait_res == WAIT_TIMEOUT) {
TerminateProcess(pi.hProcess, 1);
result = (void *)(intptr_t)-1;
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return result;
}
#endif
pthread_mutex_t readdir_mutex = PTHREAD_MUTEX_INITIALIZER;
static void *
thread_run_test(void *arg) {
DIR *cwd = arg;
struct dirent *dent;
while (1) {
pthread_mutex_lock(&readdir_mutex);
dent = readdir(cwd);
pthread_mutex_unlock(&readdir_mutex);
if (!dent) {
break;
}
const char *testname = dent->d_name;
if (!is_valid_test(testname)) {
continue;
}
fprintf(stderr, "running test %s\n", testname);
if (run_test(testname) || check_test_artefacts(testname)) {
fprintf(stderr, "[!] test %s failed\n", testname);
} else if (!silent_success) {
fprintf(stderr, "test %s ok\n", testname);
}
}
return NULL;
}
int
main(int argc, char *argv[]) {
(void)argc;
// int action = ACTION_RUN;
size_t nthreads = 1;
struct optparse opts;
optparse_init(&opts, argv);
int opt;
while ((opt = optparse(&opts, "j:s")) != -1) {
switch (opt) {
case 'j':
nthreads = strtoul(opts.optarg, NULL, 0);
break;
case 's':
silent_success = 0;
break;
default:
fprintf(stderr, "[!] Unknown option: '%c'\n", opt);
exit(1);
}
}
DIR *cwd = opendir(".");
pthread_t *threads = malloc(sizeof(pthread_t)*nthreads);
for (size_t i = 0; i < nthreads; i++) {
pthread_create(threads + i, NULL, thread_run_test, cwd);
}
for (size_t i = 0; i < nthreads; i++) {
void *retval;
pthread_join(threads[i], &retval);
}
free(threads);
return 0;
}
+14 -8
View File
@@ -6,6 +6,11 @@
/rd/1: fs=fat, start=0 (0 B), length=2880 (1440 kiB)
/> set_skin /sys/DEFAULT.SKN
status: 0
/>
/> new_sys_thread
tid: 3
/> switch_to_thread 3
/>
/> window_redraw 1
/> draw_window 10 300 5 200 0x000088 1 1 1 0 1 4 hello
/> set_pixel 0 0 0x0000ff
@@ -56,8 +61,6 @@ app_name: OS
except_mask: 0
dbg_state: 0
cur_dir:
draw_bgr_x: 0
draw_bgr_y: 0
event_mask: 0
tid: 2
state: 0x0
@@ -67,23 +70,26 @@ keyboard_mode: 0
exec_params: (null)
priority: 0
in_schedule: prev (2), next (2)
/> dump_wdata 2
/> dump_wdata 3
captionEncoding: 0
caption:
caption: hi_there
clientbox (ltwh): 5 24 291 172
draw_bgr_x: 0
draw_bgr_y: 0
thread: 3
/>
/> process_info -1
cpu_usage: 0
window_stack_position: 2
window_stack_value: 2
window_stack_position: 3
window_stack_value: 3
process_name: OS
memory_start: 0x00000000
used_memory: 4294967295 (0xffffffff)
pid: 2
pid: 3
box: 10 5 300 200
slot_state: 0
client_box: 5 24 291 172
wnd_state: 0x00
wnd_state: 0x80
/> get_skin_height
24
/> get_screen_area
+5 -1
View File
@@ -3,6 +3,10 @@ set_mouse_pos_screen 40 30
#disk_add ../img/kolibri.raw rd -c 0
ramdisk_init ../../img/kolibri.raw
set_skin /sys/DEFAULT.SKN
new_sys_thread
switch_to_thread 3
window_redraw 1
draw_window 10 300 5 200 0x000088 1 1 1 0 1 4 hello
set_pixel 0 0 0x0000ff
@@ -33,7 +37,7 @@ set_window_colors 0 0 0 0 0 0 0 0 0 0
dump_win_stack 2
dump_win_pos 2
dump_appdata 2
dump_wdata 2
dump_wdata 3
process_info -1
get_skin_height
+40 -36
View File
@@ -6,6 +6,10 @@
/> set_skin /sys/DEFAULT.SKN
status: 0
/>
/> new_sys_thread
tid: 3
/> switch_to_thread 3
/>
/> window_redraw 1
/> draw_window 2 10 4 10 0x000088 1 1 1 0 1 4 hello
/> window_redraw 2
@@ -13,8 +17,8 @@ status: 0
/> set_window_caption hi_there 0
/>
/> new_sys_thread
tid: 3
/> switch_to_thread 3
tid: 4
/> switch_to_thread 4
/>
/> window_redraw 1
/> draw_window 4 5 8 5 0x000088 1 1 1 0 1 4 hello
@@ -25,17 +29,17 @@ tid: 3
11111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
11222222222221111111111111111111111111111111
11222222222221111111111111111111111111111111
11222222222221111111111111111111111111111111
11222222222221111111111111111111111111111111
11223333332221111111111111111111111111111111
11223333332221111111111111111111111111111111
11223333332221111111111111111111111111111111
11223333332221111111111111111111111111111111
11223333332221111111111111111111111111111111
11223333332221111111111111111111111111111111
11222222222221111111111111111111111111111111
11333333333331111111111111111111111111111111
11333333333331111111111111111111111111111111
11333333333331111111111111111111111111111111
11333333333331111111111111111111111111111111
11334444443331111111111111111111111111111111
11334444443331111111111111111111111111111111
11334444443331111111111111111111111111111111
11334444443331111111111111111111111111111111
11334444443331111111111111111111111111111111
11334444443331111111111111111111111111111111
11333333333331111111111111111111111111111111
11111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
@@ -73,17 +77,17 @@ tid: 3
11111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
11222222222221111111111111111111111111111111
11222222222221111111111111111111111111111111
11222222222221111111111111111111111111111111
11222222222221111111111111111111111111111111
11222233333321111111111111111111111111111111
11222233333321111111111111111111111111111111
11222233333321111111111111111111111111111111
11222233333321111111111111111111111111111111
11222233333321111111111111111111111111111111
11222233333321111111111111111111111111111111
11222222222221111111111111111111111111111111
11333333333331111111111111111111111111111111
11333333333331111111111111111111111111111111
11333333333331111111111111111111111111111111
11333333333331111111111111111111111111111111
11333344444431111111111111111111111111111111
11333344444431111111111111111111111111111111
11333344444431111111111111111111111111111111
11333344444431111111111111111111111111111111
11333344444431111111111111111111111111111111
11333344444431111111111111111111111111111111
11333333333331111111111111111111111111111111
11111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
@@ -121,18 +125,18 @@ tid: 3
11111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
11222222222221111111111111111111111111111111
11222222222221111111111111111111111111111111
11222222222221111111111111111111111111111111
11222222222221111111111111111111111111111111
11222222222221111111111111111111111111111111
11222222222221111111111111111111111111111111
11222233333321111111111111111111111111111111
11222233333321111111111111111111111111111111
11222233333321111111111111111111111111111111
11222233333321111111111111111111111111111111
11222233333321111111111111111111111111111111
11111133333311111111111111111111111111111111
11333333333331111111111111111111111111111111
11333333333331111111111111111111111111111111
11333333333331111111111111111111111111111111
11333333333331111111111111111111111111111111
11333333333331111111111111111111111111111111
11333333333331111111111111111111111111111111
11333344444431111111111111111111111111111111
11333344444431111111111111111111111111111111
11333344444431111111111111111111111111111111
11333344444431111111111111111111111111111111
11333344444431111111111111111111111111111111
11111144444411111111111111111111111111111111
11111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
+4 -1
View File
@@ -3,6 +3,9 @@ umka_boot
ramdisk_init ../../img/kolibri.raw
set_skin /sys/DEFAULT.SKN
new_sys_thread
switch_to_thread 3
window_redraw 1
draw_window 2 10 4 10 0x000088 1 1 1 0 1 4 hello
window_redraw 2
@@ -10,7 +13,7 @@ window_redraw 2
set_window_caption hi_there 0
new_sys_thread
switch_to_thread 3
switch_to_thread 4
window_redraw 1
draw_window 4 5 8 5 0x000088 1 1 1 0 1 4 hello
+4
View File
@@ -6,6 +6,10 @@
/> set_skin /sys/DEFAULT.SKN
status: 0
/>
/> new_sys_thread
tid: 3
/> switch_to_thread 3
/>
/> load_cursor_from_file /sys/fill.cur
handle = non-zero
/> var $cur_fill
+3
View File
@@ -3,6 +3,9 @@ umka_boot
ramdisk_init ../../img/kolibri.raw
set_skin /sys/DEFAULT.SKN
new_sys_thread
switch_to_thread 3
load_cursor_from_file /sys/fill.cur
var $cur_fill
load_cursor_from_mem ./spray.cur
+4
View File
@@ -6,6 +6,10 @@
/> set_skin /sys/DEFAULT.SKN
status: 0
/>
/> new_sys_thread
tid: 3
/> switch_to_thread 3
/>
/> window_redraw 1
/> draw_window 10 300 5 200 0x000088 1 1 1 0 1 3 hello
/> window_redraw 2
+3
View File
@@ -3,6 +3,9 @@ umka_boot
ramdisk_init ../../img/kolibri.raw
set_skin /sys/DEFAULT.SKN
new_sys_thread
switch_to_thread 3
window_redraw 1
draw_window 10 300 5 200 0x000088 1 1 1 0 1 3 hello
window_redraw 2
+14 -8
View File
@@ -7,6 +7,11 @@
/rd/1: fs=fat, start=0 (0 B), length=2880 (1440 kiB)
/> set_skin /sys/DEFAULT.SKN
status: 0
/>
/> new_sys_thread
tid: 3
/> switch_to_thread 3
/>
/> window_redraw 1
/> draw_window 10 300 5 200 0x000088 1 1 1 0 1 4 hello
/> set_pixel 0 0 0x0000ff
@@ -57,8 +62,6 @@ app_name: OS
except_mask: 0
dbg_state: 0
cur_dir:
draw_bgr_x: 0
draw_bgr_y: 0
event_mask: 0
tid: 2
state: 0x0
@@ -68,23 +71,26 @@ keyboard_mode: 0
exec_params: (null)
priority: 0
in_schedule: prev (2), next (2)
/> dump_wdata 2
/> dump_wdata 3
captionEncoding: 0
caption:
caption: hi_there
clientbox (ltwh): 5 24 291 172
draw_bgr_x: 0
draw_bgr_y: 0
thread: 3
/>
/> process_info -1
cpu_usage: 0
window_stack_position: 2
window_stack_value: 2
window_stack_position: 3
window_stack_value: 3
process_name: OS
memory_start: 0x00000000
used_memory: 4294967295 (0xffffffff)
pid: 2
pid: 3
box: 10 5 300 200
slot_state: 0
client_box: 5 24 291 172
wnd_state: 0x00
wnd_state: 0x80
/> get_skin_height
24
/> get_screen_area
+5 -1
View File
@@ -4,6 +4,10 @@ set_mouse_pos_screen 40 30
#disk_add ../img/kolibri.raw rd -c 0
ramdisk_init ../../img/kolibri.raw
set_skin /sys/DEFAULT.SKN
new_sys_thread
switch_to_thread 3
window_redraw 1
draw_window 10 300 5 200 0x000088 1 1 1 0 1 4 hello
set_pixel 0 0 0x0000ff
@@ -34,7 +38,7 @@ set_window_colors 0 0 0 0 0 0 0 0 0 0
dump_win_stack 2
dump_win_pos 2
dump_appdata 2
dump_wdata 2
dump_wdata 3
process_info -1
get_skin_height
+14 -8
View File
@@ -7,6 +7,11 @@
/rd/1: fs=fat, start=0 (0 B), length=2880 (1440 kiB)
/> set_skin /sys/DEFAULT.SKN
status: 0
/>
/> new_sys_thread
tid: 3
/> switch_to_thread 3
/>
/> window_redraw 1
/> draw_window 10 300 5 200 0x000088 1 1 1 0 1 4 hello
/> set_pixel 0 0 0x0000ff
@@ -57,8 +62,6 @@ app_name: OS
except_mask: 0
dbg_state: 0
cur_dir:
draw_bgr_x: 0
draw_bgr_y: 0
event_mask: 0
tid: 2
state: 0x0
@@ -68,23 +71,26 @@ keyboard_mode: 0
exec_params: (null)
priority: 0
in_schedule: prev (2), next (2)
/> dump_wdata 2
/> dump_wdata 3
captionEncoding: 0
caption:
caption: hi_there
clientbox (ltwh): 5 24 291 172
draw_bgr_x: 0
draw_bgr_y: 0
thread: 3
/>
/> process_info -1
cpu_usage: 0
window_stack_position: 2
window_stack_value: 2
window_stack_position: 3
window_stack_value: 3
process_name: OS
memory_start: 0x00000000
used_memory: 4294967295 (0xffffffff)
pid: 2
pid: 3
box: 10 5 300 200
slot_state: 0
client_box: 5 24 291 172
wnd_state: 0x00
wnd_state: 0x80
/> get_skin_height
24
/> get_screen_area
+5 -1
View File
@@ -4,6 +4,10 @@ set_mouse_pos_screen 40 30
#disk_add ../img/kolibri.raw rd -c 0
ramdisk_init ../../img/kolibri.raw
set_skin /sys/DEFAULT.SKN
new_sys_thread
switch_to_thread 3
window_redraw 1
draw_window 10 300 5 200 0x000088 1 1 1 0 1 4 hello
set_pixel 0 0 0x0000ff
@@ -34,7 +38,7 @@ set_window_colors 0 0 0 0 0 0 0 0 0 0
dump_win_stack 2
dump_win_pos 2
dump_appdata 2
dump_wdata 2
dump_wdata 3
process_info -1
get_skin_height