The limits test reads results through the seqlock that replaced the pointer

This commit is contained in:
Joseph Ferano 2026-09-12 11:00:01 +07:00
parent 4a7eaaa425
commit 4a7b874050

View File

@ -27,7 +27,31 @@ void **flan_dev_cell(const char *name);
void flan_dev_result_begin(void);
void flan_dev_emit(const uint8_t *bytes, int64_t len);
void flan_dev_result_end(void);
const char *flan_dev_result_get(uint64_t *gen, uint64_t *len);
uint64_t flan_dev_result_cap(void);
int flan_dev_result_read(char *dst, uint64_t cap, uint64_t *gen, uint64_t *len);
/* [flan_dev_result_get] was replaced by a real seqlock, which copies into the
* caller's buffer rather than handing back a pointer into one being written.
* The buffer is sized from [flan_dev_result_cap] rather than from CAP below,
* which is this test's own expectation of the answer: sizing it from the
* number under test would make a wrong cap copy the wrong amount and agree
* with itself. */
static char rbuf[1 << 16];
static const char *result_read(uint64_t *gen, uint64_t *len) {
if (flan_dev_result_cap() > sizeof rbuf) {
printf("result buffer too small for cap %llu\n",
(unsigned long long)flan_dev_result_cap());
exit(2);
}
if (!flan_dev_result_read(rbuf, sizeof rbuf, gen, len)) {
/* Single-threaded here: the writer is this thread, so a failed read means
* the counter was left odd, not that a write was racing. */
printf("result read did not settle\n");
exit(2);
}
return rbuf;
}
void flan_rt_init(int32_t argc, char **argv);
#define CAP 4096
@ -45,7 +69,7 @@ static int cap(void) {
memset(a, 'a', sizeof a);
memset(b, 'b', sizeof b);
r = flan_dev_result_get(&gen0, &len);
r = result_read(&gen0, &len);
flan_dev_result_begin();
flan_dev_emit(a, (int64_t)sizeof a);
@ -56,7 +80,7 @@ static int cap(void) {
flan_dev_emit(b, (int64_t)sizeof b);
flan_dev_result_end();
r = flan_dev_result_get(&gen1, &len);
r = result_read(&gen1, &len);
printf("len %llu\n", (unsigned long long)len);
printf("tail %.3s\n", len >= 3 ? r + len - 3 : "");
printf("mid %c\n", len > 3500 ? r[3500] : '?');
@ -68,7 +92,7 @@ static int cap(void) {
flan_dev_result_begin();
flan_dev_emit((const uint8_t *)"12", 2);
flan_dev_result_end();
r = flan_dev_result_get(&gen1, &len);
r = result_read(&gen1, &len);
printf("again %.*s\n", (int)len, r);
return 0;
}