ChibiOS OS Library Test Suite

Discussions and support about ChibiOS/RT, the free embedded RTOS.
User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: ChibiOS OS Library Test Suite

Postby Giovanni » Thu Jan 21, 2021 8:04 am

Hi Bob,

Please hold with the fix, I have not had time to really look into it but create the ticket.

Not sure about the memory leak, we should check in which version it disappeared. There have been no recent changes in the OSLIB/allocators that could explain this.

Giovanni

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: ChibiOS OS Library Test Suite

Postby Giovanni » Sat Jan 23, 2021 11:20 am

Hi Bob,

The fix is not sufficient, it would align the size of the objects but the base address would not be necessarily aligned too, dyn_create_object_heap() requires an alignment parameter and should use chHeapAllocAligned() internally.

I am looking into it.

Giovanni

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

Re: ChibiOS OS Library Test Suite

Postby FXCoder » Sat Jan 23, 2021 11:38 am

Ok. Good point.

And the test cases could be expanded to add a test for non-aligned object size also?

Bob

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: ChibiOS OS Library Test Suite

Postby Giovanni » Sat Jan 23, 2021 11:46 am

That would be a good idea.

Giovanni

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: ChibiOS OS Library Test Suite

Postby Giovanni » Sat Jan 23, 2021 12:28 pm

I committed a tentative fix in trunk, will be backported after some review.

Giovanni

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

Re: ChibiOS OS Library Test Suite

Postby FXCoder » Sat Jan 23, 2021 2:01 pm

Hi Giovanni,
Have tested your current fix on a system that implements 2 x factory object FIFOs of different size and exercises all of the objects.
I forced the objects of one to be non-aligned and did not hit any assert or other problem so the fix looks good.
Although I've been using factory object FIFO in the above since factory was first released, the FIFOs of the system just happened to have object sizes which didn't trigger the alignment bug.
Just lucky on that.

Also have a project in development at work as well that is using multiple factory object FIFOs.
I'll update trunk of that project on Monday and test just to confirm.
--
Bob

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

Re: ChibiOS OS Library Test Suite

Postby FXCoder » Sun Jan 24, 2021 6:24 am

Hi Giovanni,
Might the below be sufficient addition to oslib_test_sequence_009.c ?
The cleanup is left to oslib_test_009_005_teardown(...).
--
Bob

Code: Select all

  /* [9.5.7] Creating a dynamic objects FIFO with alignment of objects with
     non-aligned size, must succeed.*/
  test_set_step(7);
  {
    dofp = chFactoryCreateObjectsFIFO("myfifo", 13U, 16U, PORT_NATURAL_ALIGN);
    test_assert(dofp != NULL, "cannot create");
  }
  test_end_step(7);

  /* [9.5.8] Check alignment of base and next dynamic objects in FIFO,
     must be aligned.*/
  test_set_step(8);
  {
    void *obj1, *obj2;

    objects_fifo_t * obfp = chFactoryGetObjectsFIFO(dofp);
    test_assert(obfp != NULL, "no fifo allocated");
    obj1 = chFifoTakeObjectTimeout(obfp, TIME_IMMEDIATE);
    test_assert(obj1 != NULL, "no object 1 allocated");
    test_assert(MEM_IS_ALIGNED(obj1, PORT_NATURAL_ALIGN),
                                "base of objects not aligned");
    obj2 = chFifoTakeObjectTimeout(obfp, TIME_IMMEDIATE);
    test_assert(obj2 != NULL, "no object 2 allocated");
    test_assert(MEM_IS_ALIGNED(obj2, PORT_NATURAL_ALIGN),
                                "second object not aligned");
  }
  test_end_step(8);

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: ChibiOS OS Library Test Suite

Postby Giovanni » Sun Jan 24, 2021 6:44 am

Hi Bob,

chFactoryGetObjectsFIFO() cannot return NULL so it is not necessary to test it. The two chFifoTakeObjectTimeout() should fail because the FIFO is empty.

IMO the test is not very useful because the allocator always returns block aligned, at least, to PORT_NATURAL_ALIGN so it would never fail.

It is not easy to write such a test because the outcome depends on the current heap state, you would need to create initial conditions into the heap in order to explore the results (first fragment aligned to specific boundaries). Anyway you would be testing the allocator, not the factory code, it is the allocator that does the real alignment.

Giovanni

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

Re: ChibiOS OS Library Test Suite

Postby FXCoder » Sun Jan 24, 2021 7:01 am

Agreed it is the allocator doing the work under the hood that has to get things right.
The chFifoTakeObjectTimeout(...) call allocates an object from the pool (not receive from Mbox) and thus should not fail.
Anyway if the test isn't very useful then no problem.
--
Bob

vrollei
Posts: 163
Joined: Sun Nov 13, 2016 8:44 am
Been thanked: 26 times

Re: ChibiOS OS Library Test Suite

Postby vrollei » Mon Jan 25, 2021 11:50 am

Hi,

run test against trunk version, it is the same situation:

00:00:38.314 DEBUG main.c::print_mem:51  - core free memory : 56112 bytes
00:00:38.342 DEBUG main.c::print_mem:52 - heap fragments : 2
00:00:38.367 DEBUG main.c::print_mem:53 - heap free total : 536 bytes
00:00:38.395 DEBUG main.c::print_mem:54 - heap free largest: 408 bytes
00:00:38.423 DEBUG main.c::main:194 - Iteration: 1 Errors: 0
....
00:08:43.114 DEBUG main.c::print_mem:51 - core free memory : 51120 bytes
00:08:43.142 DEBUG main.c::print_mem:52 - heap fragments : 1
00:08:43.168 DEBUG main.c::print_mem:53 - heap free total : 552 bytes
00:08:43.196 DEBUG main.c::print_mem:54 - heap free largest: 552 bytes
00:08:43.223 DEBUG main.c::main:194 - Iteration: 13 Errors: 0
Vitaly


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 13 guests