Challenge - 5 Problems
configASSERT Debugging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What happens when configASSERT fails in FreeRTOS?
Consider this snippet using configASSERT in FreeRTOS:
What is the expected behavior when this task runs?
void vTaskFunction(void *pvParameters) {
int x = 0;
configASSERT(x != 0);
// Task code
}What is the expected behavior when this task runs?
FreeRTOS
void vTaskFunction(void *pvParameters) {
int x = 0;
configASSERT(x != 0);
// Task code
}Attempts:
2 left
💡 Hint
Think about what an assert is supposed to do when a condition is false during development.
✗ Incorrect
configASSERT is designed to catch programming errors during development by halting the system or entering a safe infinite loop when the condition is false. This helps developers notice and fix bugs early.
🧠 Conceptual
intermediate1:30remaining
Why use configASSERT() only in development builds?
Why is it recommended to enable configASSERT() only during development and disable it in production?
Attempts:
2 left
💡 Hint
Think about what happens when an assertion fails and why that might be a problem in a live system.
✗ Incorrect
Assertions are meant to catch bugs early by stopping the system. In production, stopping the system abruptly can cause failures or data loss, so assertions are usually disabled.
❓ Predict Output
advanced2:00remaining
What is the output of this configASSERT macro usage?
Given the following configASSERT definition and code snippet:
What will be printed when test() is called?
#define configASSERT(x) if((x) == 0) { taskDISABLE_INTERRUPTS(); for(;;); }
void test() {
int a = 5;
configASSERT(a > 10);
printf("Passed\n");
}What will be printed when test() is called?
FreeRTOS
#define configASSERT(x) if((x) == 0) { taskDISABLE_INTERRUPTS(); for(;;); } void test() { int a = 5; configASSERT(a > 10); printf("Passed\n"); }
Attempts:
2 left
💡 Hint
Check the condition inside configASSERT and what happens if it is false.
✗ Incorrect
Since a=5 and the condition a>10 is false, configASSERT triggers the infinite loop after disabling interrupts, so printf is never reached.
🔧 Debug
advanced2:00remaining
Identify the error in this configASSERT usage
What is wrong with this configASSERT usage?
#define configASSERT(x) if(x == 0) { taskDISABLE_INTERRUPTS(); for(;;); }
void check(int val) {
configASSERT(val > 0);
printf("Value is %d\n", val);
}FreeRTOS
#define configASSERT(x) if(x == 0) { taskDISABLE_INTERRUPTS(); for(;;); } void check(int val) { configASSERT(val > 0); printf("Value is %d\n", val); }
Attempts:
2 left
💡 Hint
Consider operator precedence and how macros evaluate expressions.
✗ Incorrect
Without parentheses around x in the macro, expressions like val > 0 may not evaluate correctly, leading to unexpected behavior.
🚀 Application
expert3:00remaining
How to implement a custom configASSERT handler for debugging?
You want to customize configASSERT to log the file name and line number where the assertion failed before halting. Which of the following implementations correctly achieves this?
FreeRTOS
#define configASSERT(x) // your implementation hereAttempts:
2 left
💡 Hint
Remember that code after an infinite loop will never run.
✗ Incorrect
Option D prints the failure message before disabling interrupts and entering an infinite loop, ensuring the message is logged before halting.