#Trying to print error for comptime test function

1 messages · Page 1 of 1 (latest)

rigid axle
#

I have a test block that is failing.

How can I add debug prints?

std.debug.print doesn't work, it's just skipped.

@compileLog is helpful to figure out what branches I am going in, but I cannot print some values since they are deemed runtime values.

Trying to add prints to see where changes to this code fails https://github.com/ZigEmbeddedGroup/microzig/blob/main/port/raspberrypi/rp2xxx/src/hal/pio/assembler/comparison_tests.zig#L167

GitHub

Unified abstraction layer and HAL for several microcontrollers - ZigEmbeddedGroup/microzig

#

specifically I am trying to print the value of certain tokens in the tokenizer. I can add compile logs to see which branches are being taken, but I cannot print a token because it says its a runtime value

#
            if (cpu == .RP2350 and std.mem.startsWith(u8, peek_source_lower.slice(), "rxfifo")) {
                @compileLog("got mov from rx?", peek_source_lower.slice()); // DELETEME
                @compileError("wtf");

            }```
the branch is entered based on a runtime value (peek_source_lower), so why can't I log its value?
devout idol
#

is there a reason youre using @compileLog instead of std.debug.print?

rigid axle
#

std.debug.print isn't showing up in the output

devout idol
#

then its probably not getting called

rigid axle
#

but i am seeing the compile logs

devout idol
#

yeah because compile logs get called in runtime ifs no matter the condition

rigid axle
#

can I make the prints work even if the tests pass?

devout idol
#

what tests

rigid axle
#

I am running zig build test, the linked test is failing (with changes locally)

            if (cpu == .RP2350 and std.mem.startsWith(u8, peek_source_lower.slice(), "rxfifo")) {
                // @compileLog("got mov from rx?", peek_source_lower.slice()); // DELETEME
                // std.debug.panic("wtf", .{});
                std.debug.print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX hello {s}\n", .{peek_source_lower.slice()});
                return error.Fuck;

I see the error but not the log

#

one sec

#

I was also getting this

❯ zig build test --summary all -freference-trace
test
└─ run test
   └─ zig test Debug native 1 errors
/Users/graziano/zig/0.13.0/files/lib/std/Thread.zig:594:45: error: comptime call of extern function
                assert(c.pthread_threadid_np(null, &thread_id) == 0);
                       ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/Users/graziano/zig/0.13.0/files/lib/std/Thread.zig:277:29: note: called from here
    return Impl.getCurrentId();
           ~~~~~~~~~~~~~~~~~^~
/Users/graziano/zig/0.13.0/files/lib/std/Thread/Mutex.zig:80:47: note: called from here
        const current_id = Thread.getCurrentId();
                           ~~~~~~~~~~~~~~~~~~~^~
/Users/graziano/zig/0.13.0/files/lib/std/Thread/Mutex.zig:44:19: note: called from here
    self.impl.lock();
    ~~~~~~~~~~~~~~^~
/Users/graziano/zig/0.13.0/files/lib/std/Progress.zig:525:22: note: called from here
    stderr_mutex.lock();
    ~~~~~~~~~~~~~~~~~^~
/Users/graziano/zig/0.13.0/files/lib/std/debug.zig:84:28: note: called from here
    std.Progress.lockStdErr();
    ~~~~~~~~~~~~~~~~~~~~~~~^~
/Users/graziano/zig/0.13.0/files/lib/std/debug.zig:94:15: note: called from here
    lockStdErr();
    ~~~~~~~~~~^~
src/hal/pio/assembler/tokenizer.zig:759:28: note: called from here
            std.debug.print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX hello {s}\n", .{peek_source_lower.slice()});
            ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

it calls assemble which is also comptime, and it uses compileError to complain

devout idol
#

hm so it is running at comptime

rigid axle
#

yeah, a bit strange. I guess here I am expecting to see error when compiling the test not when running the test

devout idol
rigid axle
#

I get a log I expect, but I can't debug it since it won't print what I need
@as(*const [16:0]u8, "got mov from rx?"), @as([]const u8, [runtime value])

#

I don't understand why it's a runtime value when the call is comptime

devout idol
#

ohhh, you can try using std.fmt.comptimePrint

#

to format it properly and then log it

rigid axle
#

can't resolve comptime value

#

you're being generous with your time btw, I appreciate it

#

if you're at all willing, it's an easy repro if I push my code

#

but i don't expect you to clone and run anything to help me

devout idol
rigid axle
twilit kraken
#

Could you show the erorr that you get when you use comptimePrint?

rigid axle
# twilit kraken Could you show the erorr that you get when you use comptimePrint?

can't resolve comptime value
I've tried to convert the assemble function so that it can run at runtime. It would run at compile time normally (it's assembled and injected into the output binary). Unfortunately the way the tests work is it uses the compiled program name to compare it to an imported c header file, by accessing the struct field with program.name + some stuff