shithub: dav1d

Download patch

ref: c3a128842d7ce84074aed1a2c1ff691e12406721
parent: 95a192549a448b70d9542e840c4e34b60d09b093
author: Martin Storsjö <martin@martin.st>
date: Wed Aug 5 09:08:30 EDT 2020

checkasm: msac: Fix signal handler recovery in msac_decode_bool*

The signal handler does a longjmp back to the location of declare_func
when there's a signal. If declare_func is located within the check_func
block, it will just end up in an endless loop, retrying running the
failing tests again.

On linux, after resuming from the signal handler, the second signal
wouldn't trigger the signal handler but forcibly exit the process,
while on darwin, it would get stuck in an endless loop.

msac_decode_bool seems to be the only checkasm test with declare_func
within the check_func block.

--- a/tests/checkasm/msac.c
+++ b/tests/checkasm/msac.c
@@ -140,11 +140,11 @@
     report("decode_symbol");
 }
 
-static void check_decode_bool(MsacDSPContext *const c, uint8_t *const buf) {
+static void check_decode_bool_adapt(MsacDSPContext *const c, uint8_t *const buf) {
     MsacContext s_c, s_a;
 
+    declare_func(unsigned, MsacContext *s, uint16_t *cdf);
     if (check_func(c->bool_adapt, "msac_decode_bool_adapt")) {
-        declare_func(unsigned, MsacContext *s, uint16_t *cdf);
         uint16_t cdf[2][2];
         for (int cdf_update = 0; cdf_update <= 1; cdf_update++) {
             dav1d_msac_init(&s_c, buf, BUF_SIZE, !cdf_update);
@@ -165,9 +165,13 @@
                 bench_new(&s_a, cdf[1]);
         }
     }
+}
 
+static void check_decode_bool_equi(MsacDSPContext *const c, uint8_t *const buf) {
+    MsacContext s_c, s_a;
+
+    declare_func(unsigned, MsacContext *s);
     if (check_func(c->bool_equi, "msac_decode_bool_equi")) {
-        declare_func(unsigned, MsacContext *s);
         dav1d_msac_init(&s_c, buf, BUF_SIZE, 1);
         s_a = s_c;
         for (int i = 0; i < 64; i++) {
@@ -180,9 +184,13 @@
         }
         bench_new(&s_a);
     }
+}
 
+static void check_decode_bool(MsacDSPContext *const c, uint8_t *const buf) {
+    MsacContext s_c, s_a;
+
+    declare_func(unsigned, MsacContext *s, unsigned f);
     if (check_func(c->bool, "msac_decode_bool")) {
-        declare_func(unsigned, MsacContext *s, unsigned f);
         dav1d_msac_init(&s_c, buf, BUF_SIZE, 1);
         s_a = s_c;
         for (int i = 0; i < 64; i++) {
@@ -197,6 +205,12 @@
         bench_new(&s_a, 16384);
     }
 
+}
+
+static void check_decode_bool_funcs(MsacDSPContext *const c, uint8_t *const buf) {
+    check_decode_bool_adapt(c, buf);
+    check_decode_bool_equi(c, buf);
+    check_decode_bool(c, buf);
     report("decode_bool");
 }
 
@@ -204,8 +218,8 @@
     ALIGN_STK_16(uint16_t, cdf, 2, [16]);
     MsacContext s_c, s_a;
 
+    declare_func(unsigned, MsacContext *s, uint16_t *cdf);
     if (check_func(c->hi_tok, "msac_decode_hi_tok")) {
-        declare_func(unsigned, MsacContext *s, uint16_t *cdf);
         for (int cdf_update = 0; cdf_update <= 1; cdf_update++) {
             dav1d_msac_init(&s_c, buf, BUF_SIZE, !cdf_update);
             s_a = s_c;
@@ -272,6 +286,6 @@
         buf[i] = rnd();
 
     check_decode_symbol(&c, buf);
-    check_decode_bool(&c, buf);
+    check_decode_bool_funcs(&c, buf);
     check_decode_hi_tok(&c, buf);
 }