Skip to content

Conversation

@Nox-MSFT
Copy link
Collaborator

@Nox-MSFT Nox-MSFT commented Nov 2, 2025

This pull request introduces comprehensive improvements to the API service testing infrastructure, focusing on robust verification of cross-process communication and race condition handling. The changes include new documentation, enhanced test implementation, and codebase updates to ensure tests can safely run in parallel without resource conflicts. Additionally, the CI/CD pipeline examples have been updated to include stress testing for race conditions.

API Service Race Condition Testing and Documentation

  • Added a detailed guide for API service testing, including background on race conditions, troubleshooting steps, and CI/CD integration in docs/agent-reference/how-to-test-api-service.md.
  • Expanded documentation in README.md and docs/agent-reference/GetAduServiceStatus.md to describe API service test procedures, stress testing, and expected outputs. [1] [2] [3] [4]

Test Implementation and Infrastructure

  • Updated apisvc_unit_tests.cpp to use unique FIFO paths per test instance, synchronize test startup with service readiness, and implement robust timeout handling, enabling reliable parallel execution and race condition detection. [1] [2]
  • Added is_api_svc_ready() API and supporting logic in apisvc.c/apisvc.h to allow tests to wait for service readiness, and ensured readiness/reset flags are managed correctly. [1] [2] [3] [4] [5]
  • Updated test build configuration to use C++17 and enabled Catch2 test discovery in CMake. [1] [2]

General Test Code Cleanup

  • Removed unnecessary #include <ostream> lines from several test main files for cleaner compilation. [1] [2] [3]

CI/CD Pipeline and Platform Support

  • Added CI/CD pipeline examples for GitHub Actions and Azure DevOps to run API service race condition stress tests, and updated Docker build matrix to remove unsupported OS/arch combinations. [1] [2]

These changes collectively ensure the API service is robust against race conditions, provide clear instructions for developers and CI/CD systems, and improve reliability and maintainability of the test infrastructure.

AndreRicardo-Zoetis and others added 14 commits September 19, 2025 11:37
…sh (#761)

* Fix warnings and add test for ADUC_HashUtils_GetIndexStrongestValidHash

* Add empty line.
* Update x509 doc

* Add X.509 demo script with device-specific naming and DU config generation

- 8-step validation, dual thumbprints, IoT Hub connectivity testing
- File structure reporting and Ubuntu 20.04 disclaimer

* Fixed shellcheck error

* docs: add comprehensive X.509 testing framework with dependency management

Enhance X.509 authentication documentation and demo script with smart
dependency caching, service-aware testing, comprehensive validation,
and extensive troubleshooting guidance. Includes build automation and
compilation fixes for seamless development workflow.

* fix: resolve sign-conversion warnings in command_helper and hash_utils

- Fix safeReadSize type usage in command_helper.c
- Add explicit cast for loop index in hash_utils.c
- Improve type safety in buffer and array operations

* feat: enhance X.509 authentication with dual certificates and mandatory IoT Hub validation

- Add dual certificate generation (primary/secondary) with unique SHA1 thumbprints for X.509 authentication
- Implement mandatory IoT Hub hostname validation for agent testing scenarios
- Update demo-setup.sh with comprehensive interactive mode and enhanced certificate management
- Add Microsoft package repository setup to resolve deviceupdate-agent dependency issues
- Extend agent timeout from 15s to 60s for better testing and validation
- Update configuration schema version to 1.2 with new X.509 connection format
- Improve connection string validation logging and error messages
- Add remote debugging configuration and version updates (1.2.1-private-preview)
- Enhance X.509 documentation with production-ready certificate examples

Major improvements:
* Interactive certificate setup with device registration guidance
* Dual certificate workflow supporting IoT Hub primary/secondary thumbprints
* Smart dependency management with Microsoft repository integration
* Enhanced validation with 8-step certificate verification process
* Backward compatibility maintained through symlinks and configuration migration

Fixed shellcheck issues:
* Add -r flag to all read commands to prevent backslash interpretation
* Replace 'cat file | sed' with 'sed < file' for better efficiency
* Fix sudo redirect issue by using pipe to tee instead of direct redirection
* Add shellcheck source directive for /etc/os-release inclusion

* - Add comprehensive parameter change detection and connection testing
- Fix output hub hostname

* Update x509 demo script and document
Remove test-device-twin.sh
* Add prelim doc for GetAduServiceStatus API

* Add ADUC_ServiceStatus_Pausing

* Update description of command handler and view state manager

Clarified the explanation of how the CommandHandler interacts with the ViewStateManager and the ADU service status.

* Add packaging, pkgcfg, versioning, ipc sections

* update diagrams to include Paused state

* fix so lib name i state flow diagram

* Add apisvc get_state crossproc api

* add utils timer

* add idlePauseMilliseconds config

* Add out-of-proc SDK wrapper API, docs, and examples

* apiproto_utils

* arm64 rpi4 integration fixes

* updates to doc and unused cmake var

* fix typo and apiproto hdr lnk

* fix indent adu sdk hdr

* rmv stale doc param

* set viewstate to Failed on report json failure

* put extern g_vsm in hdr

* rev schemaVersion 1.2 du-config

* add MAX_BUF_LEN macro comment

* replace 3 sizeof u16 with MSG_HDR_LEN

* add links to yocto repo for sample yocto integration via status_monitor

* add missing file headers

* add missing file hdr for viewstatemgr

* log warn when not init'ed in getter

* add RESP_MSG_READ_BUF_SIZE
* flush and wait before close resp fifo

* further improvements for rpi4

* fix sdk examples zlog indirect dep and clangformat
* Fix example manufacturer and model fields and add IdlePauseMilliseconds to an example config
…upport

- Fix race conditions in apisvc_unit_tests.cpp with unique FIFO paths
- Add g_api_svc_ready synchronization flag to apisvc.c
- Create container-specific test suite (apisvc_container_unit_tests.cpp)
- Add enhanced debugging scripts for container environments:
  * test-apisvc-debug.sh: Comprehensive test debugging with strace
  * run-container-tests.sh: Container-aware test runner with monitoring
- Update CMakeLists.txt to include container tests with proper timeouts
- Enhance GitHub Actions workflow with container debugging capabilities
- Add comprehensive documentation for container testing best practices
- Fix all shellcheck warnings in debugging scripts

The changes address test timeouts and hanging in CI/CD container environments
while maintaining compatibility with standard testing workflows.
- Fix Catch2 include path: use catch2/catch_all.hpp instead of catch2/catch.hpp
- Fix API includes: use aduc/apiproto.h instead of aduc/proto_utils.h
- Replace high-level protocol functions with low-level wire protocol API
- Add missing filesystem include for std::filesystem usage
- Use ApiWireRequestMsg/ApiWireResponseMsg and msg_send_req/msg_recv_resp
- Match the API pattern used in the working apisvc_unit_tests.cpp

This resolves the build error: 'catch2/catch.hpp: No such file or directory'
Use 'aduc/apisvc.h' instead of 'apisvc.h' to match the working test file.
Remove duplicate include that was causing compilation errors.
Define g_vsm as a local variable instead of declaring it as extern.
This matches the pattern used in the working apisvc_unit_tests.cpp.
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