Skip to content

Conversation

@parth21999
Copy link
Member

@parth21999 parth21999 commented Jan 21, 2026

Summary

  • Add TIMED_TEST_SUITE_INITIALIZE and TIMED_TEST_SUITE_CLEANUP macros in common/inc/c_pal/timed_test_suite.h
  • Provides automatic timeout protection for integration tests using process_watchdog
  • Watchdog init runs BEFORE user suite init code
  • Watchdog deinit runs AFTER user suite cleanup code
  • Add unit tests to verify fixture ordering

Dependencies

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@parth21999
Copy link
Member Author

parth21999 commented Jan 21, 2026

/AzurePipelines run #Resolved

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@parth21999
Copy link
Member Author

parth21999 commented Jan 21, 2026

/AzurePipelines run #Resolved

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@parth21999
Copy link
Member Author

parth21999 commented Jan 21, 2026

/AzurePipelines run #Resolved

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@parth21999
Copy link
Member Author

parth21999 commented Jan 21, 2026

/AzurePipelines run #Resolved

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

build_test_folder(thandle_ptr_ut)
build_test_folder(real_thandle_log_context_handle_ut)
build_test_folder(tqueue_ut)
add_subdirectory(timed_test_suite_ut)
Copy link
Contributor

@mattdurak mattdurak Jan 21, 2026

Choose a reason for hiding this comment

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

add_subdirectory

Maybe should have a comment that it intentionally doesn't use c-testrunnerswitcher #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to use c-testrunnerswitcher.

if (timed_test_suite_ut_succeeded() != 0)
{
// Final validation of fixture ordering has failed
failedTests++;
Copy link
Contributor

@mattdurak mattdurak Jan 21, 2026

Choose a reason for hiding this comment

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

can we Log something here? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Added log

add_subdirectory(timed_test_suite_ut)
endif()

if(${run_int_tests})
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider an int test that demonstrates the timeout works. I guess since the process_watchdog will terminate, the test would probably need to launch that process and make sure it gets terminated within the timeout (+ delta)

mattdurak
mattdurak previously approved these changes Jan 21, 2026
Copy link
Contributor

@mattdurak mattdurak left a comment

Choose a reason for hiding this comment

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

:shipit:

static int call_counter = 0;

// Mock process_watchdog functions
int process_watchdog_init(uint32_t timeout_ms)
Copy link
Member

@dcristoloveanu dcristoloveanu Jan 21, 2026

Choose a reason for hiding this comment

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

process_watchdog_init

Wait, where is this used? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

This is called inside TIMED_TEST_SUITE_INITIALIZE macro.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added specs and comment.

return 0;
}

void process_watchdog_deinit(void)
Copy link
Member

@dcristoloveanu dcristoloveanu Jan 21, 2026

Choose a reason for hiding this comment

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

process_watchdog_deinit

And this one? where is it used? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

This is called inside TIMED_TEST_SUITE_CLEANUP macro.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added specs and comment

// This ensures the macros use our mock functions
#include "c_pal/timed_test_suite.h"

CTEST_BEGIN_TEST_SUITE(timed_test_suite_ut)
Copy link
Member

Choose a reason for hiding this comment

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

CTEST_BEGIN_TEST_SUITE

The mix of CTEST_ and TIMED_TEST_SUITE_INITIALIZE me does not likey

Copy link
Member Author

Choose a reason for hiding this comment

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

TIMED_TEST_SUITE_INITIALIZE/TIMED_TEST_SUITE_CLEANUP are the macros under test.

CTEST_BEGIN_TEST_SUITE/CTEST_END_TEST_SUITE are being used as the testing framework.

How else can we write these tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to use BEGIN_TEST_SUITE/END_TEST_SUITE.

Does that make it better?

// Verify watchdog deinit was called AFTER user cleanup
if (watchdog_deinit_call_order <= user_cleanup_call_order)
{
(void)printf("ERROR: watchdog_deinit_call_order (%d) should be greater than user_cleanup_call_order (%d)\r\n",
Copy link
Member

@dcristoloveanu dcristoloveanu Jan 21, 2026

Choose a reason for hiding this comment

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

printf

Aren't we in c-pal? Why do we need printf? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Changing to use LogError.

{
size_t failedTests = 0;

(void)logger_init();
Copy link
Member

@dcristoloveanu dcristoloveanu Jan 21, 2026

Choose a reason for hiding this comment

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

logger_init

Sooooo, if we fail we continue? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Added check

}
else
{
result = 0;
Copy link
Member

@dcristoloveanu dcristoloveanu Jan 21, 2026

Choose a reason for hiding this comment

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

This can be validated in the test suite cleanup and then we do not need the shoehorn-y timed_test_suite_ut_succeeded to be called from main.
I think it would make the test cleaner. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@dcristoloveanu dcristoloveanu left a comment

Choose a reason for hiding this comment

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

🕐

- Switch from CTEST_* macros to testrunnerswitcher macros for consistency
- Add LogError when fixture ordering validation fails
- Add detailed comment explaining mock function usage pattern
- Convert from add_subdirectory to build_test_folder/build_test_artifacts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
parth21999 and others added 4 commits January 21, 2026 13:43
- Replace printf with LogError in timed_test_suite_ut_succeeded()
- Handle logger_init() failure properly in main.c
- Only run tests if logger initialization succeeds

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove SRS_TIMED_TEST_SUITE_43_001 (default timeout constant) from
  requirements, code tags, and test tags
- Add timeout value assertion in process_watchdog_init mock to verify
  the correct timeout_ms is passed
- Add additional fixtures (additional_init_fixture, additional_cleanup_fixture)
  to verify variadic argument passing and fixture ordering
- Add comprehensive fixture ordering assertions throughout

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

if (logger_init() != 0)
{
(void)printf("logger_init failed\r\n");
Copy link
Member Author

Choose a reason for hiding this comment

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

(void)printf("logger_init failed\r\n");

Use LogError

// Copyright (C) Microsoft Corporation. All rights reserved.

#include <stdint.h>
#include <inttypes.h>
Copy link
Member Author

Choose a reason for hiding this comment

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

Only need inttypes, dont need stdint also

// including timed_test_suite.h, we can track when they are called to verify fixture ordering.
// Expected timeout value (must match TIMED_TEST_DEFAULT_TIMEOUT_MS from timed_test_suite.h)
#define EXPECTED_TIMEOUT_MS 600000

Copy link
Member Author

Choose a reason for hiding this comment

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

Move the above the comment explaining the mock process_watchdog functions

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

3 similar comments
@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

"user_init should be call #3");
}

/*Tests_SRS_TIMED_TEST_SUITE_43_006: [ TIMED_TEST_SUITE_CLEANUP shall call TEST_SUITE_CLEANUP with any additional fixtures passed via variadic arguments, followed by the watchdog deinit fixture as the last fixture. ]*/
Copy link
Member Author

Choose a reason for hiding this comment

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

Tests_SRS_TIMED_TEST_SUITE_43_006

Tests tag for the same requirement is placed multiple times. Place the tag only once.

#define EXPECTED_TIMEOUT_MS 600000

/*Tests_SRS_TIMED_TEST_SUITE_43_002: [ TIMED_TEST_SUITE_INITIALIZE shall create a static fixture function that calls process_watchdog_init with timeout_ms. ]*/
int process_watchdog_init(uint32_t timeout_ms)
Copy link
Member Author

Choose a reason for hiding this comment

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

process_watchdog_init

Add LogInfo in text fixtures, functions init/cleanup so that reading the test output clearly shows what happened

…leanup includes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants