From a64a7b0d0e88b549ba91fc125c5d57b5089636cb Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Tue, 30 May 2017 01:00:03 +0200 Subject: [PATCH] qa: check that notes cannot eat wait messages --- qa/kern/build.json | 1 + qa/kern/wait_note.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 qa/kern/wait_note.c diff --git a/qa/kern/build.json b/qa/kern/build.json index 2184803..08ee7e2 100644 --- a/qa/kern/build.json +++ b/qa/kern/build.json @@ -40,6 +40,7 @@ "syscall.c", "sysstatread.c", "tsemacquire.c", + "wait_note.c", "waserror.c" ] } diff --git a/qa/kern/wait_note.c b/qa/kern/wait_note.c new file mode 100644 index 0000000..540446e --- /dev/null +++ b/qa/kern/wait_note.c @@ -0,0 +1,72 @@ +/* + * This file is part of Jehanne. + * + * Copyright (C) 2017 Giacomo Tesio + * + * Jehanne is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * Jehanne is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jehanne. If not, see . + */ +#include +#include + +int +ignore_note(void *v, char *s) +{ + print("%d: note received: %s\n", getpid(), s); + return 1; +} + +void +main(void) +{ + Waitmsg *w; + int i = 0, cpid; + + if (!atnotify(ignore_note, 1)){ + fprint(2, "%r\n"); + exits("atnotify fails"); + } + switch(cpid = fork()){ + case -1: + print("FAIL: fork\n"); + exits("FAIL"); + case 0: + print("%d: child: waiting 3 sec\n", getpid()); + sleep(3000); + print("%d: child: sending note to parent\n", getpid()); + postnote(PNPROC, getppid(), "test"); + exits(0); + default: + break; + } + print("%d: start waiting for child to complete\n", getpid()); +InterruptedByNote: + w = wait(); + if(w == nil){ + if(i==0){ + ++i; + print("%d: wait interrupted by note, try again once\n", getpid()); + goto InterruptedByNote; + } + print("FAIL: no wait msg\n"); + exits("FAIL"); + } + + if(cpid != w->pid){ + print("FAIL: wrong Waitmsg: pid = %d instead of expected %d\n", w->pid, cpid); + exits("FAIL"); + } + print("Got Waitmsg for child %d\n", w->pid); + + print("PASS\n"); + exits("PASS"); +}