mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-05 04:02:28 +00:00
Build tool for hunting down flakes
This commit is contained in:
parent
93e22c581f
commit
2de3845b25
10 changed files with 78 additions and 131 deletions
|
@ -29,6 +29,7 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/sysconf.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/auxv.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
@ -104,12 +105,14 @@ done:
|
|||
}
|
||||
|
||||
TEST(cachestat, testCachestatShmem) {
|
||||
char name[64];
|
||||
sprintf(name, "/cachestat_test-%ld", _rand64());
|
||||
size_t filesize = 512 * 2 * pagesize; // 2 2MB huge pages.
|
||||
size_t compute_len = 512 * pagesize;
|
||||
unsigned long num_pages = compute_len / pagesize;
|
||||
char *data = gc(xmalloc(filesize));
|
||||
ASSERT_SYS(0, filesize, getrandom(data, filesize, 0));
|
||||
ASSERT_SYS(0, 3, shm_open("tmpshmcstat", O_CREAT | O_RDWR, 0600));
|
||||
ASSERT_SYS(0, 3, shm_open(name, O_CREAT | O_RDWR, 0600));
|
||||
ASSERT_SYS(0, 0, ftruncate(3, filesize));
|
||||
ASSERT_SYS(0, filesize, write(3, data, filesize));
|
||||
struct cachestat_range range = {pagesize, compute_len};
|
||||
|
@ -117,6 +120,6 @@ TEST(cachestat, testCachestatShmem) {
|
|||
ASSERT_SYS(0, 0, cachestat(3, &range, &cs, 0));
|
||||
ASSERT_EQ(num_pages, cs.nr_cache + cs.nr_evicted,
|
||||
"total number of cached and evicted pages is off.\n");
|
||||
ASSERT_SYS(0, 0, shm_unlink("tmpshmcstat"));
|
||||
ASSERT_SYS(0, 0, shm_unlink(name));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
|
|
@ -56,9 +56,8 @@ int threadid;
|
|||
|
||||
void WorkerQuit(int sig, siginfo_t *si, void *ctx) {
|
||||
ASSERT_EQ(SIGILL, sig);
|
||||
if (!IsXnu() && !IsOpenbsd()) {
|
||||
if (!IsXnu() && !IsOpenbsd())
|
||||
ASSERT_EQ(SI_TKILL, si->si_code);
|
||||
}
|
||||
ASSERT_EQ(threadid, gettid());
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
|
@ -18,7 +19,6 @@
|
|||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/thread/semaphore.h"
|
||||
|
||||
#define SHM_PATH "/fc7261622dd420d8"
|
||||
#define STRING_SEND "hello"
|
||||
#define STRING_RECV "HELLO"
|
||||
|
||||
|
@ -29,13 +29,14 @@ struct shmbuf {
|
|||
char buf[256]; /* Data being transferred */
|
||||
};
|
||||
|
||||
char shm_path[64];
|
||||
atomic_bool *ready;
|
||||
|
||||
wontreturn void Bouncer(void) {
|
||||
|
||||
/* Create shared memory object and set its size to the size
|
||||
of our structure. */
|
||||
int fd = shm_open(SHM_PATH, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
|
||||
int fd = shm_open(shm_path, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
|
||||
if (fd == -1) {
|
||||
perror("shm_open(bouncer)");
|
||||
exit(1);
|
||||
|
@ -96,7 +97,7 @@ wontreturn void Sender(void) {
|
|||
|
||||
/* Open the existing shared memory object and map it
|
||||
into the caller's address space. */
|
||||
int fd = shm_open(SHM_PATH, O_RDWR, 0);
|
||||
int fd = shm_open(shm_path, O_RDWR, 0);
|
||||
if (fd == -1) {
|
||||
perror("shm_open(sender)");
|
||||
exit(1);
|
||||
|
@ -136,7 +137,7 @@ wontreturn void Sender(void) {
|
|||
/* Unlink the shared memory object. Even if the peer process
|
||||
is still using the object, this is okay. The object will
|
||||
be removed only after all open references are closed. */
|
||||
if (shm_unlink(SHM_PATH)) {
|
||||
if (shm_unlink(shm_path)) {
|
||||
if (IsWindows() && errno == EACCES) {
|
||||
// TODO(jart): Make unlink() work better on Windows.
|
||||
} else {
|
||||
|
@ -154,7 +155,7 @@ int pid2;
|
|||
void OnExit(void) {
|
||||
kill(pid1, SIGKILL);
|
||||
kill(pid2, SIGKILL);
|
||||
shm_unlink(SHM_PATH);
|
||||
shm_unlink(shm_path);
|
||||
}
|
||||
|
||||
void OnTimeout(int sig) {
|
||||
|
@ -164,6 +165,9 @@ void OnTimeout(int sig) {
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
// create random shared memory name
|
||||
sprintf(shm_path, "/shm_open_test-%ld", _rand64());
|
||||
|
||||
// create synchronization object
|
||||
ready = _mapshared(1);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue