free5gc / upf

Apache License 2.0
32 stars 51 forks source link

Compile Time Errors and Segmentation Fault while running testutlt #55

Closed mohammedyaqub closed 2 years ago

mohammedyaqub commented 2 years ago

According to the documentation while running the separate testutlt binary causes Compile Time Errors and Undefined Behavior through gdb seg fault occurs due to TestTerminate() .

mkdir build
cd build
cmake ..
make -j`nproc`
cd build/bin
./testutlt

The following is the Output.

[1/14][YamlTest] : status OK
[2/14][TimerTest] : status OK
[3/14][TimeTest] : 2022-03-31T12:49:38+05:30 [ERRO][UPF][Util] TimeConvert GMT error: need 2019-08-22 14:24:47.445585 [234 Thu], not 2019-08-22 11:54:47.445585 [234 Thu]
2022-03-31T12:49:38+05:30 [ERRO][UPF][Util] TestTime_3 fail
status error
[4/14][ThreadTest] : status OK
[5/14][PoolTest] : 2022-03-31T12:49:38+05:30 [WARN][UPF][Util] Pool is empty
2022-03-31T12:49:38+05:30 [ERRO][UPF][Util] Pool is full, it may not belong to this pool
status OK
[6/14][NetworkTest] : status OK
[7/14][MqTest] : status OK
[8/14][ListTest] : status OK
[9/14][IndexTest] : status OK
[10/14][HashTest] : status OK
[11/14][EventTest] : status OK
[12/14][DebugTest] : 2022-03-31T12:49:52+05:30 [ERRO][UPF][Util] 
status OK
[13/14][BuffTest] : status OK
[14/14][3gppTypesTest] : status OK
inside `testTerminate()`
Segmentation fault

Below is the function which causes seg fault and memory leak. Following is the source path lib/utlt/src/utlt_test.c

Status TestTerminate() {

    for (TestNode *it = ListFirst(&testSelf.node); it != NULL; it = ListNext(it)) {
        ListRemove(it);
        free(it);
    }

    testSelf.finishCase = 0;
    testSelf.totalCase = 0;

    return STATUS_OK;
}

And memory leaks.

LEAK SUMMARY:
==20635==    definitely lost: 68,224 bytes in 8 blocks
==20635==    indirectly lost: 0 bytes in 0 blocks
==20635==      possibly lost: 2,016 bytes in 7 blocks
==20635==    still reachable: 5,168 bytes in 15 blocks
==20635==         suppressed: 0 bytes in 0 blocks
==20635== Reachable blocks (those to which a pointer was found) are not shown.

As a request would you please look into this @free5gc-org.

ianchen0119 commented 2 years ago

Hi @mohammedyaqub, I sent the PR #56 for solving the segmentation fault problem.

Moreover, If you confused on the time testing error, you can check the time zone in your system environment first:

timedatectl

If the result doesn't match with your actual time zone, you can use the following commands for calibration:

timedatectl list-timezones # select the correct time zone
sudo timedatectl set-timezone TIME_ZONE_NAME

Thanks.

mohammedyaqub commented 2 years ago

Hi @ianchen0119 Thank you for fixing the segmentation fault. Further about compiling As suggested I check the time zone and its looks matching with current date and time.

 Local time: Tue 2022-04-19 20:08:03 IST
                  Universal time: Tue 2022-04-19 14:38:03 UTC
                        RTC time: Tue 2022-04-19 14:38:03
                       Time zone: Asia/Kolkata (IST, +0530)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

Although the compilation issue are still same. Below is the output could you please check.

[1/14][YamlTest] : status OK
[2/14][TimerTest] : status OK
[3/14][TimeTest] : 2022-04-19T20:17:27+05:30 [ERRO][UPF][Util] TimeConvert GMT error: need 2019-08-22 14:24:47.445585 [234 Thu], not 2019-08-22 11:54:47.445585 [234 Thu]
2022-04-19T20:17:27+05:30 [ERRO][UPF][Util] TestTime_3 fail
status error
[4/14][ThreadTest] : status OK
[5/14][PoolTest] : 2022-04-19T20:17:27+05:30 [WARN][UPF][Util] Pool is empty
2022-04-19T20:17:27+05:30 [ERRO][UPF][Util] Pool is full, it may not belong to this pool
status OK
[6/14][NetworkTest] : status OK
[7/14][MqTest] : status OK
[8/14][ListTest] : status OK
[9/14][IndexTest] : status OK
[10/14][HashTest] : status OK
[11/14][EventTest] : status OK
[12/14][DebugTest] : 2022-04-19T20:17:38+05:30 [ERRO][UPF][Util] 
status OK
[13/14][BuffTest] : status OK
[14/14][3gppTypesTest] : status OK
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 0
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 1
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 2
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 3
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 4
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 5
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 6
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 7
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 8
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 9
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 10
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 11
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 12
2022-04-19T20:17:38+05:30 [INFO][UPF][Util] Remove test node 13
ianchen0119 commented 2 years ago

@mohammedyaqub I think I gave the wrong information with you, you should try to switch the time zone to the Asia/Taipei because of the compared data is expect the GMT+8.

sudo timedatectl set-timezone Asia/Taipei

Thanks.

mohammedyaqub commented 2 years ago

@ianchen0119 Now its works fine thank you for correction.

Further any help regarding previously mentioned UTLT_Error(Pool is full, it may not belong to this pool);would be appreciated. As still confused with warning Pool is empty,UTLT_Error Pool is full with status as OK, mentioned in below Output at[5/14][PoolTest]. And [12/14][DebugTest] with status OK.

[1/14][YamlTest] : status OK 
[2/14][TimerTest] : status OK
[3/14][TimeTest] : status OK
[4/14][ThreadTest] : status OK
[5/14][PoolTest] : 2022-04-20T13:59:03+08:00 [WARN][UPF][Util] Pool is empty
2022-04-20T13:59:03+08:00 [ERRO][UPF][Util] Pool is full, it may not belong to this pool
status OK
[6/14][NetworkTest] : status OK
[7/14][MqTest] : status OK
[8/14][ListTest] : status OK
[9/14][IndexTest] : status OK
[10/14][HashTest] : status OK
[11/14][EventTest] : status OK
[12/14][DebugTest] : 2022-04-20T13:59:17+08:00 [ERRO][UPF][Util] 
status OK
[13/14][BuffTest] : status OK
[14/14][3gppTypesTest] : status OK
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 0
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 1
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 2
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 3
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 4
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 5
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 6
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 7
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 8
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 9
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 10
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 11
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 12
2022-04-20T13:59:17+08:00 [INFO][UPF][Util] Remove test node 13

Below is the macro defination.

#define PoolFree(__nameptr, __assignedPtr) do { \
    pthread_mutex_lock(&(__nameptr)->lock); \
    if (PoolSize(__nameptr) < (__nameptr)->qCap) { \
        (__nameptr)->queueAvail[(__nameptr)->qEnd] = (__assignedPtr); \
        (__nameptr)->qEnd = ((__nameptr)->qEnd + 1) % ((__nameptr)->qCap + 1); \
        UTLT_Debug("Pool Free successful, total capacity[%d], available[%d]" \
        , PoolCap(__nameptr), PoolSize(__nameptr)); \
    } else { \
        UTLT_Error("Pool is full, it may not belong to this pool"); \
    } \
    pthread_mutex_unlock(&(__nameptr)->lock); \
} while(0)

Thanks.