ChibiOS OS Library Test Suite

Discussions and support about ChibiOS/RT, the free embedded RTOS.
vrollei
Posts: 163
Joined: Sun Nov 13, 2016 8:44 am
Been thanked: 26 times

ChibiOS OS Library Test Suite

Postby vrollei » Wed Nov 18, 2020 9:35 pm

Hi,

ChibiOS OS Library Test Suite Test Case 9.5 (Dynamic Objects FIFOs Factory) constantly fails after about 100 iterations.
Is it possible to use oslib_test_suite inside loop?

*** ChibiOS OS Library Test Suite
***
*** Compiled: Nov 17 2020 - 15:43:13
*** Platform: STM32L4xx Ultra Low Power
*** Test Board: XBOARD
***
*** Text size: 52184 bytes
*** RO data size: 13104 bytes
*** Data size: 332 bytes
*** BSS size: 8520 bytes

----------------------------------------------------------------------------
--- Test Case 9.5 (Dynamic Objects FIFOs Factory)
--- Result: FAILURE (#2 [] "cannot create")
----------------------------------------------------------------------------
Vitaly

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 » Wed Nov 18, 2020 9:54 pm

This could be caused by memory fragmentation, the factory uses memory allocation, check the heap state using the "mem" shell command.

Giovanni

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

Re: ChibiOS OS Library Test Suite

Postby vrollei » Wed Nov 18, 2020 10:13 pm

Will check it, is there any way to clean up memory after test cases execution?
Thanks!
Vitaly

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 » Wed Nov 18, 2020 10:33 pm

vrollei wrote:Will check it, is there any way to clean up memory after test cases execution?
Thanks!


Currently not, it would require resetting the heap state which could create unintended consequences. You may try calling again the memory allocators initializers which are not an official API.

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 » Wed Nov 18, 2020 11:25 pm

Hi,
I just did a quick check on a L432 NUCLEO and found main memory decreased after each 'test oslib'.
Could it be that a factory object is not being released (left dangling with heap allocated)?
--
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 » Thu Nov 19, 2020 7:37 am

FXCoder wrote:Hi,
I just did a quick check on a L432 NUCLEO and found main memory decreased after each 'test oslib'.
Could it be that a factory object is not being released (left dangling with heap allocated)?
--
Bob


It is possible, do you know in which test case this happens?

Giovanni

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

Re: ChibiOS OS Library Test Suite

Postby vrollei » Thu Nov 19, 2020 6:42 pm

Hi,

Memory usage trace:

============================================================================
=== Test Sequence 9 (Objects Factory)
----------------------------------------------------------------------------
--- Test Case 9.1 (Objects Registry)
--- Result: SUCCESS
00:03:02.494 DEBUG main.c::print_mem:51 - core free memory : 50696 bytes
00:03:02.522 DEBUG main.c::print_mem:52 - heap fragments : 1
00:03:02.548 DEBUG main.c::print_mem:53 - heap free total : 552 bytes
00:03:02.576 DEBUG main.c::print_mem:54 - heap free largest: 552 bytes
----------------------------------------------------------------------------
--- Test Case 9.2 (Dynamic Buffers Factory)
--- Result: SUCCESS
00:03:02.836 DEBUG main.c::print_mem:51 - core free memory : 50696 bytes
00:03:02.864 DEBUG main.c::print_mem:52 - heap fragments : 1
00:03:02.890 DEBUG main.c::print_mem:53 - heap free total : 136 bytes
00:03:02.917 DEBUG main.c::print_mem:54 - heap free largest: 136 bytes
----------------------------------------------------------------------------
--- Test Case 9.3 (Dynamic Semaphores Factory)
--- Result: SUCCESS
00:03:03.179 DEBUG main.c::print_mem:51 - core free memory : 50696 bytes
00:03:03.207 DEBUG main.c::print_mem:52 - heap fragments : 1
00:03:03.232 DEBUG main.c::print_mem:53 - heap free total : 136 bytes
00:03:03.260 DEBUG main.c::print_mem:54 - heap free largest: 136 bytes
----------------------------------------------------------------------------
--- Test Case 9.4 (Dynamic Mailboxes Factory)
--- Result: SUCCESS
00:03:03.521 DEBUG main.c::print_mem:51 - core free memory : 50696 bytes
00:03:03.549 DEBUG main.c::print_mem:52 - heap fragments : 1
00:03:03.575 DEBUG main.c::print_mem:53 - heap free total : 136 bytes
00:03:03.603 DEBUG main.c::print_mem:54 - heap free largest: 136 bytes
----------------------------------------------------------------------------
--- Test Case 9.5 (Dynamic Objects FIFOs Factory)
--- Result: SUCCESS
00:03:03.865 DEBUG main.c::print_mem:51 - core free memory : 50280 bytes
00:03:03.893 DEBUG main.c::print_mem:52 - heap fragments : 1
00:03:03.918 DEBUG main.c::print_mem:53 - heap free total : 552 bytes
00:03:03.946 DEBUG main.c::print_mem:54 - heap free largest: 552 bytes




Core free memory decreases after each iteration:


00:08:04.790 DEBUG main.c::print_mem:51  - core free memory : 47784 bytes
00:08:04.818 DEBUG main.c::print_mem:52 - heap fragments : 1
00:08:04.844 DEBUG main.c::print_mem:53 - heap free total : 552 bytes
00:08:04.871 DEBUG main.c::print_mem:54 - heap free largest: 552 bytes
--------------------------------------------------------------------------
Vitaly

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 17, 2021 1:19 am

Hi Giovanni,
I started looking into the memory leak based on data Vitaly provided and the Objects FIFO tests in particular.
One thing I noticed first up is what looks like an issue with undersized heap being allocated for aligned objects.
When allocating heap shouldn't the object size be rounded up to the object alignment requirement?

The actual memory leak problem is another matter TBD.
--
Bob

Code: Select all

dyn_objects_fifo_t *chFactoryCreateObjectsFIFO(const char *name,
                                               size_t objsize,
                                               size_t objn,
                                               unsigned objalign) {
  dyn_objects_fifo_t *dofp;

  F_LOCK();

// Round up object size to aligned size here...
  dofp = (dyn_objects_fifo_t *)dyn_create_object_heap(name,
                                                      &ch_factory.fifo_list,
                                                      sizeof (dyn_objects_fifo_t) +
                                                      (objn * sizeof (msg_t)) +
                                                      (objn * objsize));
  if (dofp != NULL) {
    msg_t *msgbuf = (msg_t *)(dofp + 1);

    /* Initializing mailbox object data.*/
    chFifoObjectInitAligned(&dofp->fifo, objsize, objn, objalign,
                            (void *)&msgbuf[objn], msgbuf);
  }

  F_UNLOCK();

  return dofp;
}

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 » Mon Jan 18, 2021 1:35 pm

I tested with a non-aligned object size and hit the assert at chFifoObjectInitAligned(...) line 128.
I used the following macro to round up object size in chFactoryCreateObjectsFIFO(...) and all is OK.

Code: Select all

  objsize = MEM_ALIGN_NEXT(objsize, objalign);

--
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 » Thu Jan 21, 2021 5:09 am

Hi Giovanni and Vitaly,
#1 The memory leak
It no longer appears when I run test oslib on the same L432 board+code that I tested on previously.
So it is not clear if other recent OS change(s) may have cured the memory leak.

Vitaly - could you run your tests again on the latest trunk please?

#2 The alignment bug/fix
This is not related to the memory leak (I tested for the leak with and without the alignment fix).
The alignment fix needs to be applied in any case.

Giovanni - If you are OK with my fix I will raise a bug report and apply the fix to trunk and 20.3.x.
--
Bob


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 20 guests