]> Nishi Git Mirror - dataworks.git/commitdiff
test
authornishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Tue, 18 Jun 2024 02:11:54 +0000 (02:11 +0000)
committernishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Tue, 18 Jun 2024 02:11:54 +0000 (02:11 +0000)
git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@326 d4a5a174-5a4a-5b4b-b672-37683c10d7d5

.github/workflows/build.yml
Makefiles/test.mk
RemoteClient/hayes.c
RemoteClient/rcli.c
RemoteClient/tcpip.c
Server/server.c
Tool/Makefile
Tool/test.c [new file with mode: 0644]

index 824931561edd74f07f601723926e74be97cae257..aae2014c0b2d1b8bfd4cd5143818a6432b345403 100644 (file)
@@ -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
index c5c976b0be7629bf44f10425ddf59ef32395dc23..0dce00d6aa2405139bd44f4a303a6a9625079ed2 100644 (file)
@@ -3,3 +3,4 @@
 .PHONY: test
 
 test: no-doc
+       ./Tool/test -s "$(EXEC_SUFFIX)"
index 5a4d4c20902e6844284df5a684526decad1236e6..90d8bd00d00afa20e217a1136264d9798e3fe46e 100644 (file)
@@ -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]);
index cdb1280426e41e809e20b34db5ad515db79d4b71..be717e62ad9ab36b0cb1bcdd49b8c1d47ef38746 100644 (file)
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include <dataworks.h>
 #include <dw_util.h>
@@ -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;
index fda57882997a95454818a142f3c2063b9ca308d4..faaa344d57c6ed66a1a80ff96da19e9e596ff6fb 100644 (file)
@@ -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]);
index 16bb626678d43c1c64917a63c8ec37d5cb659313..edb3faca39144179ca90a53fa16856e3b46ea02a 100644 (file)
@@ -39,6 +39,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 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();
 }
index 5fd0d48a18eb24e3b0de59a2aaa15f2dd93a143b..2eae4ef34a5f963c9b160dd64ec58411f33faf4a 100644 (file)
@@ -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 (file)
index 0000000..d4e9036
--- /dev/null
@@ -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 <fcntl.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <unistd.h>
+
+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;
+}