From: nishi Date: Tue, 18 Jun 2024 02:11:54 +0000 (+0000) Subject: test X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=c52e657166c885ea7027b709e7078167446dfd01;p=dataworks.git test git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@326 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8249315..aae2014 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -180,6 +180,22 @@ jobs: name: build-dosimg path: install.img + test: + + name: "Test" + + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install packages + run: sudo apt install flex byacc make graphviz + - name: Make + run: make YACC=byacc test release: @@ -190,7 +206,7 @@ jobs: permissions: contents: write - needs: [build-generic, build-mac, build-debpkg, build-dosimg] + needs: [build-generic, build-mac, build-debpkg, build-dosimg, test] steps: - name: Checkout diff --git a/Makefiles/test.mk b/Makefiles/test.mk index c5c976b..0dce00d 100644 --- a/Makefiles/test.mk +++ b/Makefiles/test.mk @@ -3,3 +3,4 @@ .PHONY: test test: no-doc + ./Tool/test -s "$(EXEC_SUFFIX)" diff --git a/RemoteClient/hayes.c b/RemoteClient/hayes.c index 5a4d4c2..90d8bd0 100644 --- a/RemoteClient/hayes.c +++ b/RemoteClient/hayes.c @@ -42,6 +42,7 @@ extern int argc; extern char** argv; +extern bool usr1sig; int port = -1; bool connected = false; @@ -123,6 +124,8 @@ int rcli_init(void) { fprintf(stderr, "Invalid port: %s\n", argv[i]); return 1; } + } else if(option(argv[i], "s", "signal")) { + usr1sig = true; } else if(option(argv[i], "h", "help")) { printf("\n"); printf("Usage: %s [options] dial\n", argv[0]); diff --git a/RemoteClient/rcli.c b/RemoteClient/rcli.c index cdb1280..be717e6 100644 --- a/RemoteClient/rcli.c +++ b/RemoteClient/rcli.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -44,6 +45,7 @@ int argc; char** argv; +bool usr1sig = false; int rcli_init(void); char* readline_sock(void); @@ -240,6 +242,12 @@ int main(int _argc, char** _argv) { } printf(". "); fflush(stdout); +#if !defined(__WATCOMC__) && !defined(__MINGW32__) + if(usr1sig) { + /* Server is ready, raise SIGUSR1 */ + kill(getppid(), SIGUSR1); + } +#endif while(true) { int len = fread(cbuf, 1, 1, stdin); if(len <= 0) break; diff --git a/RemoteClient/tcpip.c b/RemoteClient/tcpip.c index fda5788..faaa344 100644 --- a/RemoteClient/tcpip.c +++ b/RemoteClient/tcpip.c @@ -60,6 +60,7 @@ extern int argc; extern char** argv; +extern bool usr1sig; int port = 4096; int sock; @@ -79,6 +80,8 @@ int rcli_init(void) { if(option(argv[i], "p", "port")) { i++; port = atoi(argv[i]); + } else if(option(argv[i], "s", "signal")) { + usr1sig = true; } else if(option(argv[i], "h", "help")) { printf("\n"); printf("Usage: %s [options] host\n", argv[0]); diff --git a/Server/server.c b/Server/server.c index 16bb626..edb3fac 100644 --- a/Server/server.c +++ b/Server/server.c @@ -39,6 +39,7 @@ #include #include #include +#include int argc; char** argv; @@ -316,9 +317,11 @@ int main(int _argc, char** _argv) { fprintf(stderr, "Failed to open databse\n"); return 1; } +#if !defined(__WATCOMC__) && !defined(__MINGW32__) if(usr1sig) { /* Server is ready, raise SIGUSR1 */ - raise(SIGUSR1); + kill(getppid(), SIGUSR1); } +#endif server_loop(); } diff --git a/Tool/Makefile b/Tool/Makefile index 5fd0d48..2eae4ef 100644 --- a/Tool/Makefile +++ b/Tool/Makefile @@ -3,13 +3,16 @@ .SUFFIXES: .c .o .PHONY: all clean -all: docfmt +all: docfmt test docfmt: docfmt.o cc -std=c99 -o $@ docfmt.o +test: test.o + cc -std=c99 -o $@ test.o + .c.o: - cc -std=c99 -c -o $@ $< + cc -D_DEFAULT_SOURCE -std=c99 -c -o $@ $< clean: rm -f docfmt *.o diff --git a/Tool/test.c b/Tool/test.c new file mode 100644 index 0000000..d4e9036 --- /dev/null +++ b/Tool/test.c @@ -0,0 +1,224 @@ +/* $Id$ */ +/* --- START LICENSE --- */ +/* -------------------------------------------------------------------------- */ +/* DataWorks - Simple DBMS */ +/* -------------------------------------------------------------------------- */ +/* Copyright (c) 2024 Crabware. */ +/* Copyright (c) 2024 pnsk-lab. */ +/* Redistribution and use in source and binary forms, with or without modific */ +/* ation, are permitted provided that the following conditions are met: */ +/* 1. Redistributions of source code must retain the above copyright noti */ +/* ce, this list of conditions and the following disclaimer. */ +/* 2. Redistributions in binary form must reproduce the above copyright n */ +/* otice, this list of conditions and the following disclaimer in the documen */ +/* tation and/or other materials provided with the distribution. */ +/* 3. Neither the name of the copyright holder nor the names of its contr */ +/* ibutors may be used to endorse or promote products derived from this softw */ +/* are without specific prior written permission. */ +/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */ +/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */ +/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */ +/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */ +/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */ +/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */ +/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */ +/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */ +/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */ +/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */ +/* OF SUCH DAMAGE. */ +/* -------------------------------------------------------------------------- */ +/* --- END LICENSE --- */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char* __util_strdup(const char* a) { + char* str = malloc(strlen(a) + 1); + memcpy(str, a, strlen(a)); + str[strlen(a)] = 0; + return str; +} + +char* __util_strcat(const char* a, const char* b) { + char* str = malloc(strlen(a) + strlen(b) + 1); + memcpy(str, a, strlen(a)); + memcpy(str + strlen(a), b, strlen(b)); + str[strlen(a) + strlen(b)] = 0; + return str; +} + +char* suffix; +pid_t pid; +pid_t pid2; + +int exist_exec(const char* og) { + char* path; + path = __util_strcat(og, suffix); + printf("Checking if %s exists... ", path); + fflush(stdout); + if(access(path, F_OK) == 0) { + printf("yes\n"); + free(path); + return 0; + } else { + printf("no\n"); + free(path); + return 1; + } +} + +int create_db(void) { + printf("Creating the database... "); + fflush(stdout); + char* path = __util_strcat("./Client/dataworks", suffix); + char* sh = __util_strcat(path, " --create db.dwf -f /dev/null >/dev/null 2>/dev/null"); + int st = system(sh); + free(sh); + free(path); + if(st == 0) { + printf("ok\n"); + return 0; + } else { + printf("fail\n"); + return 1; + } +} + +int check_db(void) { + printf("Checking the database... "); + fflush(stdout); + char* path = __util_strcat("./Client/dataworks", suffix); + char* sh = __util_strcat(path, " db.dwf -f /dev/null >/dev/null 2>/dev/null"); + int st = system(sh); + free(sh); + free(path); + if(st == 0) { + printf("ok\n"); + return 0; + } else { + printf("fail\n"); + return 1; + } +} + +bool await = true; + +void usr1hand(int sig) { await = false; } + +int server(void) { + await = true; + printf("Starting the server... "); + fflush(stdout); + char* path = __util_strcat("./Server/dataworks_server", suffix); + pid = fork(); + if(pid == 0) { + int null = open("/dev/null", O_RDWR); + dup2(null, 1); + dup2(null, 2); + execl(path, path, "-s", "db.dwf", NULL); + free(path); + printf("fail\n"); + return 1; + } else if(pid == -1) { + free(path); + printf("fail\n"); + return 1; + } + free(path); + int at = 1; + while(await) { + printf("%d... ", at++); + fflush(stdout); + sleep(1); + if(at > 3) { + int status; + waitpid(pid, &status, WNOHANG); + if(WIFEXITED(status)) { + printf("fail\n"); + return 1; + } + } + } + printf("ok\n"); + return 0; +} + +int rcli(void) { + await = true; + printf("Starting the remote client... "); + fflush(stdout); + char* path = __util_strcat("./RemoteClient/dataworks_remote_client", suffix); + pid2 = fork(); + if(pid2 == 0) { + int null = open("/dev/null", O_RDWR); + dup2(null, 1); + dup2(null, 2); + execl(path, path, "-s", "127.0.0.1", NULL); + free(path); + printf("fail\n"); + return 1; + } else if(pid2 == -1) { + free(path); + printf("fail\n"); + return 1; + } + free(path); + int at = 1; + while(await) { + printf("%d... ", at++); + fflush(stdout); + sleep(1); + if(at > 3) { + int status; + waitpid(pid2, &status, WNOHANG); + if(WIFEXITED(status) && WEXITSTATUS(status) != 0) { + printf("fail\n"); + return 1; + } + } + } + printf("ok\n"); + return 0; +} + +int main(int argc, char** argv) { + int i; + suffix = __util_strdup(""); + signal(SIGUSR1, usr1hand); + for(i = 1; i < argc; i++) { + if(strcmp(argv[i], "-s") == 0) { + i++; + free(suffix); + suffix = __util_strdup(argv[i]); + } + } + printf("Testing DataWorks\n"); + int st; + if((st = exist_exec("./Client/dataworks")) != 0) return st; + if((st = exist_exec("./Server/dataworks_server")) != 0) return st; + if((st = exist_exec("./RemoteClient/dataworks_remote_client")) != 0) return st; + printf("All executables present\n"); + if((st = create_db()) != 0) return st; + if((st = check_db()) != 0) return st; + if((st = server()) != 0) return st; + if((st = rcli()) != 0) { + kill(pid, SIGINT); + int status; + waitpid(pid, &status, 0); + return st; + } + kill(pid, SIGINT); + kill(pid2, SIGINT); + int status; + waitpid(pid, &status, 0); + waitpid(pid2, &status, 0); + return 0; +}