mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 00:02:28 +00:00
Delete flaky tests
Signals are extremely difficult to unit test reliably. This is why functions like sigsuspend() exist. When testing something else and portably it becomes impossible without access to kernel internals. OpenMP flakes in QEMU on one of my workstations. I don't think the support is production worthy, because there's been issues on MacOS additionally. It works great for every experiment I've used it for though. However a flaky test is worse than no test at all. So it's removed until someone takes an interest in productionizing it.
This commit is contained in:
parent
5488f0b2ca
commit
8a44f913ae
4 changed files with 2 additions and 616 deletions
|
@ -25,6 +25,7 @@
|
|||
#include "libc/runtime/syslib.internal.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/sock/struct/sockaddr.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
#include "libc/sysv/consts/ipproto.h"
|
||||
|
@ -107,7 +108,7 @@ TEST(O_NONBLOCK, canBeTunedWithFcntl_toMakeReadNonBlocking) {
|
|||
PARENT();
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
ASSERT_SYS(0, 3, socket(AF_INET, SOCK_STREAM, IPPROTO_TCP));
|
||||
ASSERT_SYS(0, O_RDWR, fcntl(3, F_GETFL));
|
||||
ASSERT_SYS(0, O_RDWR, fcntl(3, F_GETFL) & O_ACCMODE); // QEMU O_LARGEFILE :(
|
||||
ASSERT_SYS(0, 0, connect(3, (struct sockaddr *)&addr, sizeof(addr)));
|
||||
ASSERT_SYS(0, 0, fcntl(3, F_SETFL, O_RDWR | O_NONBLOCK));
|
||||
ASSERT_SYS(EAGAIN, -1, read(3, buf, 16));
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2024 Cadence Ember │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/isystem/errno.h"
|
||||
#include "libc/isystem/sched.h"
|
||||
#include "libc/isystem/signal.h"
|
||||
#include "libc/isystem/stddef.h"
|
||||
#include "libc/isystem/unistd.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
#define MY_TEST_STRING_1 "He"
|
||||
#define MY_TEST_STRING_2 "llo world!"
|
||||
|
||||
char buf[20] = {0};
|
||||
int pipes[2];
|
||||
int pid;
|
||||
int got_sigusr1 = 0;
|
||||
|
||||
// -=- these get called for each test ------------------------------------------
|
||||
|
||||
void sigusr1_handler(int) {
|
||||
got_sigusr1 = 1;
|
||||
}
|
||||
|
||||
void write_pipe(int send_signal_before_end) {
|
||||
// Set up pipe for writing
|
||||
close(pipes[0]);
|
||||
FILE *stream = fdopen(pipes[1], "w");
|
||||
|
||||
// Start writing the first part of the stream
|
||||
fputs(MY_TEST_STRING_1, stream);
|
||||
|
||||
// Send SIGUSR1 to parent (if we're currently testing that)
|
||||
if (send_signal_before_end) {
|
||||
kill(getppid(), SIGUSR1);
|
||||
}
|
||||
|
||||
// Send rest of stream
|
||||
fputs(MY_TEST_STRING_2, stream);
|
||||
// Close stream - this will cause the parent's fgets to end
|
||||
fclose(stream);
|
||||
}
|
||||
|
||||
void read_pipe() {
|
||||
// Set up pipe for reading
|
||||
close(pipes[1]);
|
||||
FILE *stream = fdopen(pipes[0], "r");
|
||||
|
||||
// Read with fgets
|
||||
fgets(buf, 20, stream);
|
||||
|
||||
// Tidy up
|
||||
fclose(stream);
|
||||
}
|
||||
|
||||
// -=- these set up the tests --------------------------------------------------
|
||||
|
||||
void SetUpOnce(void) {
|
||||
cpu_set_t set;
|
||||
CPU_ZERO(&set);
|
||||
CPU_SET(1, &set);
|
||||
if (sched_setaffinity(0, sizeof set, &set) == -1) {
|
||||
perror("sched_setaffinity");
|
||||
fprintf(stderr, "single core affinity is needed for test reliability\n");
|
||||
_exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void setup_signal_and_pipe(uint64_t sa_flags) {
|
||||
// Set up SIGUSR1 handler
|
||||
struct sigaction sa = {.sa_handler = sigusr1_handler, .sa_flags = sa_flags};
|
||||
if (sigaction(SIGUSR1, &sa, NULL) == -1) {
|
||||
perror("sigaction");
|
||||
_exit(1);
|
||||
}
|
||||
got_sigusr1 = 0;
|
||||
|
||||
// Set up pipe between parent and child
|
||||
if (pipe(pipes) == -1) {
|
||||
perror("pipe");
|
||||
_exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// -=- these are the tests -----------------------------------------------------
|
||||
|
||||
TEST(fgets_eintr, testThatFgetsReadsFromPipeNormally) {
|
||||
setup_signal_and_pipe(0); // 0 = no SA_RESTART
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
write_pipe(0); // 0 = no signal
|
||||
_exit(0);
|
||||
}
|
||||
read_pipe();
|
||||
EXPECT_STREQ(MY_TEST_STRING_1 MY_TEST_STRING_2, buf);
|
||||
}
|
||||
|
||||
TEST(fgets_eintr, testThatTheSignalInterruptsFgets) {
|
||||
setup_signal_and_pipe(0); // 0 = no SA_RESTART
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
write_pipe(1); // 1 = signal
|
||||
_exit(0);
|
||||
}
|
||||
read_pipe();
|
||||
EXPECT_STRNE(MY_TEST_STRING_1 MY_TEST_STRING_2, buf);
|
||||
EXPECT_EQ(EINTR, errno);
|
||||
EXPECT_EQ(1, got_sigusr1);
|
||||
}
|
||||
|
||||
TEST(fgets_eintr, testThatFgetsRestartsWhenSaRestartIsSet) {
|
||||
setup_signal_and_pipe(SA_RESTART); // SA_RESTART
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
write_pipe(1); // 1 = signal
|
||||
_exit(0);
|
||||
}
|
||||
read_pipe();
|
||||
EXPECT_STREQ(MY_TEST_STRING_1 MY_TEST_STRING_2, buf);
|
||||
EXPECT_NE(EINTR, errno);
|
||||
EXPECT_EQ(1, got_sigusr1);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue