Skip to content

Allow passing config as a fixture#78

Merged
jk-ozlabs merged 3 commits intoCodeConstruct:mainfrom
khangng-ampere:khangng/push-wnzlykommpko
Jun 3, 2025
Merged

Allow passing config as a fixture#78
jk-ozlabs merged 3 commits intoCodeConstruct:mainfrom
khangng-ampere:khangng/push-wnzlykommpko

Conversation

@khangng-ampere
Copy link
Copy Markdown
Contributor

This MR adds the capability to write tests for mctpd as an endpoint. This caught an uninitialized read bug on link data.

@khangng-ampere
Copy link
Copy Markdown
Contributor Author

Weird, I can run and pass all the test locally. Is there anyway I can view the logs? (Or I guess another PR for printing the log file on CI? 😄)

@jk-ozlabs
Copy link
Copy Markdown
Member

I'll see if I can reproduce here; if that's also passing, maybe a CI update would be handy...

@jk-ozlabs
Copy link
Copy Markdown
Member

Yeah, all passes here too - not sure what's up with the runner environment...

Comment thread src/mctpd.c Outdated
On non-bus-owner modes, link->slot_busowner will be uninitialized,
leading to segmentation fault when running sd_bus_slot_unref.

    ==3850684== Conditional jump or move depends on uninitialised value(s)
    ==3850684==    at 0x48FB448: sd_bus_slot_unref (in /usr/lib/aarch64-linux-gnu/libsystemd.so.0.38.0)
    ==3850684==    by 0x1123E3: free_link (mctpd.c:3263)
    ==3850684==    by 0x1125CB: free_links (mctpd.c:3308)
    ==3850684==    by 0x113D63: main (mctpd.c:3900)

Simply zero initialize the link data.

Signed-off-by: Khang D Nguyen <khangng@os.amperecomputing.com>
@khangng-ampere
Copy link
Copy Markdown
Contributor Author

Seems like ASAN caught some more bugs, I can reproduce with meson setup build -Db_sanitize=address just like how CI does. Let me see what it is and push a fix.

@jk-ozlabs
Copy link
Copy Markdown
Member

OK, I had a run here with -Db_sanitize=address work fine (maybe my ASAN isn't picky enough!). Let me know what you find/fix there.

ASAN complained about this config file path memory leak. Free it on
program exit.

Also, there is a clangd warning on implicitly freeing const char*.
Instead of casting to void* explicitly, I changed it to be char* to
reflect the fact that we own the string allocation better.

Signed-off-by: Khang D Nguyen <khangng@os.amperecomputing.com>
mctpd now requests a config fixture, which is None by default to ensure
previous behaviour.

Test authors can now override the config using pytest fixtures
overriding facility. An example on overriding per file basis is
included in the commit.

Signed-off-by: Khang D Nguyen <khangng@os.amperecomputing.com>
@khangng-ampere khangng-ampere force-pushed the khangng/push-wnzlykommpko branch from 6471906 to b2463e1 Compare June 3, 2025 05:26
@khangng-ampere
Copy link
Copy Markdown
Contributor Author

CI passed now. There was a memory leak when we copied the config file path from CLI args.

@jk-ozlabs jk-ozlabs merged commit b2463e1 into CodeConstruct:main Jun 3, 2025
1 check passed
@khangng-ampere khangng-ampere deleted the khangng/push-wnzlykommpko branch June 3, 2025 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants