aboutsummaryrefslogtreecommitdiff
path: root/tests/test_workspace.c
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-17 00:41:54 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-17 00:41:54 +0200
commitecc202ac078d5cb5c61d60268fce5ac46bac1e87 (patch)
treec78e32d022c07cac6f499e80b6c3c3f83bad9b44 /tests/test_workspace.c
parenteb7112ae055dda38da52b07449a7e1cf62005702 (diff)
downloadffwd-ecc202ac078d5cb5c61d60268fce5ac46bac1e87.tar.gz
ffwd-ecc202ac078d5cb5c61d60268fce5ac46bac1e87.zip
cpu: reject negative current capacity in grow_cap
Diffstat (limited to 'tests/test_workspace.c')
-rw-r--r--tests/test_workspace.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_workspace.c b/tests/test_workspace.c
index c8b6ee8..64b7404 100644
--- a/tests/test_workspace.c
+++ b/tests/test_workspace.c
@@ -8,6 +8,8 @@
#include "tiny_model.h"
#include "tok_fixture.h"
+#include "../src/alloc.h"
+
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@@ -24,6 +26,23 @@ static float max_abs_diff(const float *a, const float *b, int n) {
return m;
}
+static int check_alloc_helpers(void) {
+ int cap = 0;
+ if (grow_cap(-1, 1, &cap) == 0) {
+ fprintf(stderr, "grow_cap accepted a negative current capacity\n");
+ return -1;
+ }
+ if (grow_cap(33, 17, &cap) != 0 || cap != 33) {
+ fprintf(stderr, "grow_cap failed to preserve a larger current capacity\n");
+ return -1;
+ }
+ if (grow_cap(0, 17, &cap) != 0 || cap != 32) {
+ fprintf(stderr, "grow_cap failed to round new capacity to granularity\n");
+ return -1;
+ }
+ return 0;
+}
+
/* The allocating and pooling API variants must agree with the *_into
* results validated in main. reference is the batched row for ids0. */
static int check_alloc_and_pooling_variants(const embed_model_t *model,
@@ -161,6 +180,9 @@ done:
}
int main(int argc, char **argv) {
+ if (check_alloc_helpers() != 0)
+ return 1;
+
char fixture_dir[1024];
const char *model_dir;
if (argc == 2) {