diff --git a/userspace/include/unit/io.h b/userspace/include/unit/io.h index 1fd0fa432..ffe22a41e 100644 --- a/userspace/include/unit/io.h +++ b/userspace/include/unit/io.h @@ -60,6 +60,21 @@ struct unit_module; #define unit_err(unit, msg, ...) \ __unit_info_color(unit, C_RED, msg, ##__VA_ARGS__) + +/* + * helper to check a condition, output and error if condition is false + * and execute bail_out_code +*/ +#define unit_assert(cond, bail_out_code) \ +do { \ + if (!(cond)) { \ + unit_err(m, "%s:%d (" #cond ") is false\n", \ + __func__, __LINE__); \ + bail_out_code; \ + } \ +} while (0) + + /* * Don't go overboard with these!!! */ diff --git a/userspace/units/fifo/tsg/nvgpu-tsg.c b/userspace/units/fifo/tsg/nvgpu-tsg.c index eaed682d9..9db08fccc 100644 --- a/userspace/units/fifo/tsg/nvgpu-tsg.c +++ b/userspace/units/fifo/tsg/nvgpu-tsg.c @@ -55,11 +55,7 @@ } while (0) #endif -struct test_tsg_args { - bool init_done; - struct nvgpu_tsg *tsg; - struct nvgpu_channel *ch; -}; +#define assert(cond) unit_assert(cond, goto done) struct test_tsg_args test_args = { .init_done = false,