0
0
FreeRTOSprogramming~20 mins

configASSERT() for development debugging in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
configASSERT Debugging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What happens when configASSERT fails in FreeRTOS?
Consider this snippet using configASSERT in FreeRTOS:
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
}
AThe assertion is ignored and a warning message is printed to the console.
BThe system automatically restarts the task without any warning.
CThe system halts or enters an infinite loop to indicate the assertion failure.
DThe task continues running normally without any interruption.
Attempts:
2 left
💡 Hint
Think about what an assert is supposed to do when a condition is false during development.
🧠 Conceptual
intermediate
1:30remaining
Why use configASSERT() only in development builds?
Why is it recommended to enable configASSERT() only during development and disable it in production?
ABecause configASSERT() can halt the system, which is undesirable in production environments.
BBecause configASSERT() improves system performance in production.
CBecause configASSERT() automatically fixes bugs in production code.
DBecause configASSERT() disables all interrupts permanently.
Attempts:
2 left
💡 Hint
Think about what happens when an assertion fails and why that might be a problem in a live system.
Predict Output
advanced
2:00remaining
What is the output of this configASSERT macro usage?
Given the following configASSERT definition and code snippet:
#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");
}
APassed
BNothing is printed; the system enters an infinite loop.
CCompilation error due to missing semicolon.
DRuntime error: division by zero.
Attempts:
2 left
💡 Hint
Check the condition inside configASSERT and what happens if it is false.
🔧 Debug
advanced
2: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);
}
AThe macro lacks parentheses around the condition, causing incorrect evaluation.
BThe macro will cause a syntax error due to missing braces.
CThe macro disables interrupts but does not halt the system.
DThe macro will always print the value regardless of the assertion.
Attempts:
2 left
💡 Hint
Consider operator precedence and how macros evaluate expressions.
🚀 Application
expert
3: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 here
A#define configASSERT(x) if(x) { printf("Assertion failed at %s:%d\n", __FILE__, __LINE__); taskDISABLE_INTERRUPTS(); }
B#define configASSERT(x) if(!(x)) { taskDISABLE_INTERRUPTS(); for(;;); printf("Assertion failed\n"); }
C#define configASSERT(x) if(x == 0) { for(;;); printf("Error at line %d\n", __LINE__); }
D#define configASSERT(x) if((x) == 0) { printf("Assertion failed at %s:%d\n", __FILE__, __LINE__); taskDISABLE_INTERRUPTS(); for(;;); }
Attempts:
2 left
💡 Hint
Remember that code after an infinite loop will never run.