ref: ec2a902acc1c05ed0a95c26249bbda4032c668e7
parent: 32b537dbdb56584c3dfdb9f95f1d1cec0359d7d7
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Nov 17 20:24:06 EST 2024
mp tests: apparently they only printed the errors, never exiting with non-zero code; fix everything
--- a/3rd/mp/mptoi.c
+++ b/3rd/mp/mptoi.c
@@ -23,19 +23,10 @@
{
mpdigit x;
- if(b->top==0)
+ if(b->top == 0)
return 0;
x = *b->p;
- if(b->sign > 0){
- if(b->top > 1 || x > INT32_MAX)
- x = (int)INT32_MAX;
- else
- x = (int)x;
- } else {
- if(b->top > 1 || x > (mpdigit)INT32_MAX+1)
- x = (int)INT32_MIN;
- else
- x = -(int)x;
- }
+ x = b->sign > 0 ? ((b->top > 1 || x > INT32_MAX) ? (int)INT32_MAX : (int)x)
+ : ((b->top > 1 || x > INT32_MAX) ? (int)INT32_MIN : -(int)x);
return x;
}
--- a/3rd/mp/mptov.c
+++ b/3rd/mp/mptov.c
@@ -46,7 +46,7 @@
if(v > INT64_MAX)
v = INT64_MAX;
}else{
- v = v > (uint64_t)INT64_MIN ? INT64_MIN : -(int64_t)v;
+ v = v > INT64_MAX ? INT64_MIN : -(int64_t)v;
}
return (int64_t)v;
--- a/3rd/mp/test/convtest.c
+++ b/3rd/mp/test/convtest.c
@@ -32,6 +32,7 @@
mpfree(m); \
if(!fail) \
fprintf(stderr, #_func": passed\n"); \
+ anyfail |= fail; \
}
#define XTOMP(_name,_type,_func) \
@@ -63,6 +64,7 @@
if(!fail) \
fprintf(stderr, #_func": passed\n"); \
USED(v); \
+ anyfail |= fail; \
}
MPTOX(test_mptoi, int, mptoi)
--- a/3rd/mp/test/dat.h
+++ b/3rd/mp/test/dat.h
@@ -6,3 +6,5 @@
};
enum {NTEST = 2 * 257 + 32};
+
+extern int anyfail;
--- a/3rd/mp/test/gen.tab.c
+++ b/3rd/mp/test/gen.tab.c
@@ -2,6 +2,7 @@
#include "mp.h"
#include "dat.h"
#include "fns.h"
+
static void
testcmp(void)
{
@@ -42,6 +43,7 @@
ldfree(l3);
mpfree(m3);
if(!fail) fprintf(stderr, "mpcmp: passed\n");
+ anyfail |= fail;
}
static void
testmagcmp(void)
@@ -83,6 +85,7 @@
ldfree(l3);
mpfree(m3);
if(!fail) fprintf(stderr, "mpmagcmp: passed\n");
+ anyfail |= fail;
}
static void
testadd(void)
@@ -168,6 +171,7 @@
ldfree(l4);
mpfree(m4);
if(!fail) fprintf(stderr, "mpadd: passed\n");
+ anyfail |= fail;
}
static void
testsub(void)
@@ -253,6 +257,7 @@
ldfree(l4);
mpfree(m4);
if(!fail) fprintf(stderr, "mpsub: passed\n");
+ anyfail |= fail;
}
static void
testmagadd(void)
@@ -338,6 +343,7 @@
ldfree(l4);
mpfree(m4);
if(!fail) fprintf(stderr, "mpmagadd: passed\n");
+ anyfail |= fail;
}
static void
testmagsub(void)
@@ -423,6 +429,7 @@
ldfree(l4);
mpfree(m4);
if(!fail) fprintf(stderr, "mpmagsub: passed\n");
+ anyfail |= fail;
}
static void
testand(void)
@@ -508,6 +515,7 @@
ldfree(l4);
mpfree(m4);
if(!fail) fprintf(stderr, "mpand: passed\n");
+ anyfail |= fail;
}
static void
testbic(void)
@@ -593,6 +601,7 @@
ldfree(l4);
mpfree(m4);
if(!fail) fprintf(stderr, "mpbic: passed\n");
+ anyfail |= fail;
}
static void
testor(void)
@@ -678,6 +687,7 @@
ldfree(l4);
mpfree(m4);
if(!fail) fprintf(stderr, "mpor: passed\n");
+ anyfail |= fail;
}
static void
testxor(void)
@@ -763,6 +773,7 @@
ldfree(l4);
mpfree(m4);
if(!fail) fprintf(stderr, "mpxor: passed\n");
+ anyfail |= fail;
}
static void
testnot(void)
@@ -812,6 +823,7 @@
ldfree(l3);
mpfree(m3);
if(!fail) fprintf(stderr, "mpnot: passed\n");
+ anyfail |= fail;
}
static void
testleft(void)
@@ -864,6 +876,7 @@
ldfree(l4);
mpfree(m4);
if(!fail) fprintf(stderr, "mpleft: passed\n");
+ anyfail |= fail;
}
static void
testright(void)
@@ -916,6 +929,7 @@
ldfree(l4);
mpfree(m4);
if(!fail) fprintf(stderr, "mpright: passed\n");
+ anyfail |= fail;
}
static void
testasr(void)
@@ -968,6 +982,7 @@
ldfree(l4);
mpfree(m4);
if(!fail) fprintf(stderr, "mpasr: passed\n");
+ anyfail |= fail;
}
static void
testdiv_(void)
@@ -1148,6 +1163,7 @@
ldfree(l5);
mpfree(m5);
if(!fail) fprintf(stderr, "mpdiv_: passed\n");
+ anyfail |= fail;
}
void
tests(void)
--- a/3rd/mp/test/main.c
+++ b/3rd/mp/test/main.c
@@ -6,6 +6,7 @@
double D_PNAN, D_NNAN, D_PINF, D_NINF;
float F_PNAN, F_NNAN, F_PINF, F_NINF;
+int anyfail = 0;
void
prng(uint8_t *p, int n)
@@ -28,5 +29,5 @@
convtests();
tests();
- return 0;
+ return anyfail;
}