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

external/error_report: Add Infinity wait error reporting feature to T… #2329

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/examples/err_report_demo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ install:

endif

ifeq ($(CONFIG_BUILTIN_APPS)$(CONFIG_EXAMPLES_RT_ERR_REPORT),yy)
ifeq ($(CONFIG_BUILTIN_APPS)$(CONFIG_EXAMPLES_ERR_REPORT),yy)
$(BUILTIN_REGISTRY)$(DELIM)$(FUNCNAME).bdat: $(DEPCONFIG) Makefile
$(Q) $(call REGISTER,$(APPNAME),$(FUNCNAME),$(THREADEXEC),$(PRIORITY),$(STACKSIZE))

Expand Down
76 changes: 73 additions & 3 deletions apps/examples/err_report_demo/err_report_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#define RT_MSG(msg) printf("%s: %s\n", __BASE_FILE__, msg)
sem_t g_err_sem;
sem_t g_sem1;
sem_t g_sem2;
uint8_t g_err_nscenarios;
uint8_t g_err_nsuccess;

Expand Down Expand Up @@ -84,7 +86,7 @@ uint8_t g_err_nsuccess;
* WiFi Manager callback prototypes
*/
static void prv_sta_connected(wifi_manager_result_e);
static void prv_sta_disconnected(void);
static void prv_sta_disconnected(wifi_manager_disconnect_e res);
static void prv_softap_sta_join(void);
static void prv_softap_sta_leave(void);
static void prv_scan_done(wifi_manager_scan_info_s **scan_result, wifi_manager_scan_result_e res);
Expand All @@ -98,7 +100,7 @@ static void prv_sta_connected(wifi_manager_result_e res)
ERR_REPORT_TEST_SIGNAL;
}

static void prv_sta_disconnected(void)
static void prv_sta_disconnected(wifi_manager_disconnect_e res)
{
sleep(2);
printf(" [RT] T%d --> %s\n", getpid(), __FUNCTION__);
Expand Down Expand Up @@ -162,7 +164,7 @@ static void error_report_single(const char *endpoint)
char readbuf[1024];
int nbytes_read = 0;
int nbytes_sent = 0;

error_report_init();
res = wifi_manager_init(&wifi_callbacks);
if (res != WIFI_MANAGER_SUCCESS) {
printf(" wifi_manager_init fail\n");
Expand Down Expand Up @@ -191,6 +193,7 @@ static void error_report_single(const char *endpoint)
wifi_manager_disconnect_ap();
ERR_REPORT_TEST_WAIT;
wifi_manager_deinit();
error_report_deinit();
ERR_REPORT_TC_END_CHECK(nbytes_sent > 0);
}

Expand All @@ -207,6 +210,7 @@ static void error_report_multiple(const char *endpoint)
int sock_cnt = 0;
int sock_fds[CONFIG_NSOCKET_DESCRIPTORS];

error_report_init();
res = wifi_manager_init(&wifi_callbacks);
if (res != WIFI_MANAGER_SUCCESS) {
printf(" wifi_manager_init fail\n");
Expand Down Expand Up @@ -259,6 +263,7 @@ static void error_report_multiple(const char *endpoint)
wifi_manager_disconnect_ap();
ERR_REPORT_TEST_WAIT;
wifi_manager_deinit();
error_report_deinit();
ERR_REPORT_TC_END_CHECK(nbytes_sent > 0);
}

Expand All @@ -273,6 +278,67 @@ static void error_report_queue_underflow(void)
ERR_REPORT_TC_END_CHECK(nbytes_read == 0);
}

static int prv_thread1(void *args)
{
sem_wait(&g_sem1);
sem_post(&g_sem2);
return 0;
}

static int prv_thread2(void *args)
{
sem_wait(&g_sem2);
sem_post(&g_sem1);
return 0;
}

static void error_report_infinity_wait(const char *endpoint)
{
ERR_REPORT_TC_START;
wifi_manager_result_e res = WIFI_MANAGER_SUCCESS;
wifi_manager_ap_config_s apconfig = { "Gorani", 6, "jonbeo1@", 8, WIFI_MANAGER_AUTH_WPA2_PSK, WIFI_MANAGER_CRYPTO_AES };
pthread_t thread1;
pthread_t thread2;
int r;
int scenario_success = -1;
error_report_init();

error_report_start_infinitywait();
res = wifi_manager_init(&wifi_callbacks);
if (res != WIFI_MANAGER_SUCCESS) {
printf(" wifi_manager_init fail\n");
goto done;
}

res = wifi_manager_connect_ap(&apconfig);
if (res != WIFI_MANAGER_SUCCESS) {
printf(" AP connect failed\n");
goto done;
}
/* Wait for DHCP connection */
ERR_REPORT_TEST_WAIT;
sem_init(&g_sem1, 0, 0);
sem_init(&g_sem2, 0, 0);
if ((r = pthread_create(&thread1, NULL, (pthread_startroutine_t)prv_thread1, NULL)) != 0) {
goto done;
}

pthread_create(&thread2, NULL, (pthread_startroutine_t) prv_thread2, NULL);
/* Sleep for a sufficient amount of time, after which the infinity wait should be seen */
sleep(CONFIG_ERROR_REPORT_INFINITE_CHECK_TIMER * (CONFIG_ERROR_REPORT_INFINITE_CHECK_THRESHOLD + 1));
scenario_success = 1;
done:
wifi_manager_disconnect_ap();
ERR_REPORT_TEST_WAIT;
wifi_manager_deinit();
error_report_deinit();
pthread_cancel(thread1);
pthread_join(thread1, NULL);
pthread_cancel(thread2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should call pthread_join or pthread_detach to prevent memory leak.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. I will implement as you suggest.

pthread_join(thread2, NULL);
ERR_REPORT_TC_END_CHECK(scenario_success > 0);
}

static void error_report_test(const char *endpoint)
{
ERR_REPORT_LOG_START;
Expand All @@ -285,6 +351,10 @@ static void error_report_test(const char *endpoint)
/* Verify multiple errors across WiFi Manager */
error_report_multiple(endpoint);

/* Verify Infinite Wait */
#ifdef CONFIG_ERROR_REPORT_INFINITE_WAIT
error_report_infinity_wait(endpoint);
#endif
ERR_REPORT_PRINT_STATS;
ERR_REPORT_LOG_END;
}
Expand Down
36 changes: 35 additions & 1 deletion external/error_report/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,39 @@ config EPORT_ERROR_REPORT
default "5001"
---help---
Enter Port of endpoint server where error logs will be gathered


config ERROR_REPORT_INFINITE_WAIT
bool "Report error for infinitely waiting threads"
default n
select SCHED_CPULOAD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you make a dependancy with SCHED_CPULOAD?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done because the feature needs CPULOAD monitoring for it to work.

---help---
Report error if threads wait infinitely long

if ERROR_REPORT_INFINITE_WAIT

config ERROR_REPORT_INFINITE_CHECK_TIMER
int "Timeout in seconds to check for infinite wait"
default 6
---help---
Specify timeout value after which to check for infinite waits

config ERROR_REPORT_INFINITE_CHECK_THRESHOLD
int "Number of observed interations of thread inactivity"
default 3
---help---
Specify number of iterations of thread inactivity after which to report as error

config ERROR_REPORT_NTHREADS_IN_WAIT
int "Number of threads (max) to be reported as waiting"
default 8
---help---
Specify number of threads (max) in wait

config ERROR_REPORT_BACKTRACE_MAX_DEPTH
int "Number of functions to report from callstack"
default 6
---help---
Specify depth of the backtrace

endif #ERROR_REPORT_INFINITE_WAIT
endif # ERROR_REPORT
Loading