Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for allocation errors #740

Open
gavv opened this issue Jun 23, 2024 · 1 comment
Open

Add unit tests for allocation errors #740

gavv opened this issue Jun 23, 2024 · 1 comment
Labels
easy hacks The solution is expected to be straightforward even if you are new to the project help wanted An important and awaited task but we have no human resources for it yet tests

Comments

@gavv
Copy link
Member

gavv commented Jun 23, 2024

Many pipeline elements take core::IArena as an argument and perform some allocations in constructor. If allocations fails, the convention is to report error (StatusNoMem) via init_status() method.

We need to cover this behavior with unit tests. For each element, we need to add one test that creates the element using mock, which always fails (e.g. core::NoopArena). Then we should check that the element returned StatusNoMem via init_status().

Elements to cover:

  • ChannelMapperReader
  • ChannelMapperWriter
  • PcmMapperReader
  • PcmMapperWriter
  • ProfilingReader
  • ProfilingWriter
  • Mixer
@gavv gavv added tests help wanted An important and awaited task but we have no human resources for it yet easy hacks The solution is expected to be straightforward even if you are new to the project labels Jun 23, 2024
@gavv gavv added this to Roc Toolkit Jul 6, 2024
@gavv gavv moved this to Help wanted in Roc Toolkit Jul 6, 2024
@KBoumghar
Copy link

KBoumghar commented Jan 5, 2025

Hey, willing to help for this, but I'm new to the project so I'm a bit lost (bear with me please :) ). Let's take ChannelMapperReader for example, from what I understand, we'd want something like :

TEST(channel_mapper_reader, empty_allocation) {
    enum { FrameSz = MaxSz / 2 };

    const SampleSpec in_spec(MaxSz, Sample_RawFormat, ChanLayout_Surround,
                             ChanOrder_Smpte, ChanMask_Surround_Mono);
    const SampleSpec out_spec(MaxSz, Sample_RawFormat, ChanLayout_Surround,
                              ChanOrder_Smpte, ChanMask_Surround_Stereo);

    const core::nanoseconds_t start_ts = 1000000;

    test::MockReader mock_reader;
    ChannelMapperReader mapper_reader(mock_reader, core::NoopArena, in_spec, out_spec);
    
    //Somehow check here if mapper_reader here has StatusNoMem
}

couple questions :

  1. Is the "signature" for TEST good (well I'm guessing empty_allocation is not a super good name)? I'm not exactly sure how TEST is called and my only experience with tests in C++ comes from using GTest. From reading a bit it seems to be first argument is the "object" it's testing and second is what it's testing, but just wanted to make sure.

  2. I tried grepping for init_status in the repo, but couldn't find it. Grepping for StatusNoMem and looking at other tests, it seems like they're getting a status out of some methods (e.g. meter.write()) and then doing a LONGS_EQUAL to compare that to StatusNoMem. We also have the is_valid(), but that's not the status being talked about in your message, but seems like other use of core::NoopArena just check for that.

What I'm guessing here is that the test is on another "level" (not the components themselves) and I'm missing something / reading what you wrote wrongly. Any pointers would be appreciated :) !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy hacks The solution is expected to be straightforward even if you are new to the project help wanted An important and awaited task but we have no human resources for it yet tests
Projects
Status: Help wanted
Development

No branches or pull requests

2 participants