Skip to content

Comments

tests: full white-box coverage for all public interfaces + fix process_table_destroy double-destroy segfault#54

Merged
HiGarfield merged 5 commits intomasterfrom
copilot/refactor-cpulimit-test-coverage
Feb 21, 2026
Merged

tests: full white-box coverage for all public interfaces + fix process_table_destroy double-destroy segfault#54
HiGarfield merged 5 commits intomasterfrom
copilot/refactor-cpulimit-test-coverage

Conversation

Copy link

Copilot AI commented Feb 20, 2026

  • Explore all .h/.c files, build and run existing 71-test suite
  • Bug fix in process_table.c: process_table_destroy now zeros pt->hashsize
  • Makefile fix: include cli.c in test build
  • Add 29 new tests (71 → 100) across all modules
  • Fix: replace non-ASCII en-dash with ASCII hyphen - in all 9 section header comments
  • Fix: wrap it.dip == NULL assertion in #if defined(__linux__) for portability
  • Build gcc + clang CHECK=1 — zero warnings/errors
  • 100 tests ALL PASSED

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: HiGarfield <32226909+HiGarfield@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve unit test coverage and revert output redirection tests: full white-box coverage + fix stdout suppression (freopen → close) Feb 20, 2026
Copilot AI requested a review from HiGarfield February 20, 2026 23:45
…li.c fix

Co-authored-by: HiGarfield <32226909+HiGarfield@users.noreply.github.com>
Copilot AI changed the title tests: full white-box coverage + fix stdout suppression (freopen → close) tests: full white-box coverage for all public interfaces + fix Makefile to link cli.c Feb 21, 2026
…ouble-destroy segfault

Co-authored-by: HiGarfield <32226909+HiGarfield@users.noreply.github.com>
Copilot AI changed the title tests: full white-box coverage for all public interfaces + fix Makefile to link cli.c tests: full white-box coverage for all public interfaces + fix process_table_destroy double-destroy segfault Feb 21, 2026
@HiGarfield HiGarfield marked this pull request as ready for review February 21, 2026 00:38
Copilot AI review requested due to automatic review settings February 21, 2026 00:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves robustness and confidence in cpulimit by fixing a process_table_destroy double-destroy segfault and expanding the C unit test suite to cover previously untested branches (including parse_arguments by linking cli.c into the test binary).

Changes:

  • Fix process_table_destroy to clear hashsize after freeing the bucket array, preventing a second destroy from dereferencing a NULL table.
  • Update the test build to link src/cli.c, enabling parse_arguments tests.
  • Add extensive white-box tests across modules to increase branch/boundary/error-path coverage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.

File Description
src/process_table.c Prevents double-destroy segfault by zeroing hashsize after teardown.
tests/Makefile Links cli.c into cpulimit_test so CLI parsing is testable.
tests/cpulimit_test.c Adds many new white-box tests, including CLI parsing and edge/error paths.

}

/***************************************************************************
* LIST MODULE – ADDITIONAL COVERAGE
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

This comment header uses a non-ASCII en dash ("–"). AGENTS.md requires ASCII-only source/comments, which can also break builds depending on compiler/locale. Replace it with an ASCII hyphen (-).

Suggested change
* LIST MODULE ADDITIONAL COVERAGE
* LIST MODULE - ADDITIONAL COVERAGE

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

Fixed in 621e2f1 — replaced all 9 en-dash characters with ASCII hyphens - in the section header comments.

}

/***************************************************************************
* UTIL MODULE – ADDITIONAL COVERAGE
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

This comment header uses a non-ASCII en dash ("–"). AGENTS.md requires ASCII-only source/comments. Replace it with an ASCII hyphen (-).

Suggested change
* UTIL MODULE ADDITIONAL COVERAGE
* UTIL MODULE - ADDITIONAL COVERAGE

Copilot uses AI. Check for mistakes.
}

/***************************************************************************
* PROCESS_TABLE MODULE – ADDITIONAL COVERAGE
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

This comment header uses a non-ASCII en dash ("–"). AGENTS.md requires ASCII-only source/comments. Replace it with an ASCII hyphen (-).

Suggested change
* PROCESS_TABLE MODULE ADDITIONAL COVERAGE
* PROCESS_TABLE MODULE - ADDITIONAL COVERAGE

Copilot uses AI. Check for mistakes.
}

/***************************************************************************
* SIGNAL_HANDLER MODULE – ADDITIONAL COVERAGE
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

This comment header uses a non-ASCII en dash ("–"). AGENTS.md requires ASCII-only source/comments. Replace it with an ASCII hyphen (-).

Suggested change
* SIGNAL_HANDLER MODULE ADDITIONAL COVERAGE
* SIGNAL_HANDLER MODULE - ADDITIONAL COVERAGE

Copilot uses AI. Check for mistakes.
}

/***************************************************************************
* PROCESS_GROUP MODULE – ADDITIONAL COVERAGE
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

This comment header uses a non-ASCII en dash ("–"). AGENTS.md requires ASCII-only source/comments. Replace it with an ASCII hyphen (-).

Suggested change
* PROCESS_GROUP MODULE ADDITIONAL COVERAGE
* PROCESS_GROUP MODULE - ADDITIONAL COVERAGE

Copilot uses AI. Check for mistakes.
}

/***************************************************************************
* LIMIT_PROCESS MODULE – ADDITIONAL COVERAGE
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

This comment header uses a non-ASCII en dash ("–"). AGENTS.md requires ASCII-only source/comments. Replace it with an ASCII hyphen (-).

Suggested change
* LIMIT_PROCESS MODULE ADDITIONAL COVERAGE
* LIMIT_PROCESS MODULE - ADDITIONAL COVERAGE

Copilot uses AI. Check for mistakes.
Comment on lines 3416 to 3418
assert(init_process_iterator(&it, &filter) == 0);
/* dip is NULL because single-PID optimisation skips opendir() */
assert(it.dip == NULL);
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

test_process_iterator_close_null_dip reaches into struct process_iterator internals (it.dip). That field only exists on Linux (process_iterator.h uses #if defined(__linux__)), so this test will not compile on FreeBSD/macOS. Prefer asserting only on public behavior (e.g., close_process_iterator(&it) == 0) or wrap the it.dip assertion in #if defined(__linux__).

Suggested change
assert(init_process_iterator(&it, &filter) == 0);
/* dip is NULL because single-PID optimisation skips opendir() */
assert(it.dip == NULL);
assert(init_process_iterator(&it, &filter) == 0);
#if defined(__linux__)
/* dip is NULL because single-PID optimisation skips opendir() */
assert(it.dip == NULL);
#endif

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

Fixed in 621e2f1 — the it.dip assertion is now guarded with #if defined(__linux__) so the test compiles cleanly on FreeBSD and macOS.

}

/***************************************************************************
* PROCESS_ITERATOR MODULE – ADDITIONAL COVERAGE
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

This comment header uses a non-ASCII en dash ("–"). AGENTS.md requires ASCII-only source/comments. Replace it with an ASCII hyphen (-).

Suggested change
* PROCESS_ITERATOR MODULE ADDITIONAL COVERAGE
* PROCESS_ITERATOR MODULE - ADDITIONAL COVERAGE

Copilot uses AI. Check for mistakes.
Comment on lines 3520 to 3522
/***************************************************************************
* LIMITER MODULE – ADDITIONAL COVERAGE
***************************************************************************/
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

This comment header uses a non-ASCII en dash ("–"). AGENTS.md requires ASCII-only source/comments. Replace it with an ASCII hyphen (-).

Copilot uses AI. Check for mistakes.
Comment on lines 3593 to 3595
/***************************************************************************
* CLI MODULE – ADDITIONAL COVERAGE
***************************************************************************/
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

This comment header uses a non-ASCII en dash ("–"). AGENTS.md requires ASCII-only source/comments. Replace it with an ASCII hyphen (-).

Copilot uses AI. Check for mistakes.
@HiGarfield
Copy link
Owner

@copilot apply changes based on the comments in this thread

…x ifdef

Co-authored-by: HiGarfield <32226909+HiGarfield@users.noreply.github.com>
@HiGarfield HiGarfield merged commit 02c3608 into master Feb 21, 2026
@HiGarfield HiGarfield deleted the copilot/refactor-cpulimit-test-coverage branch February 21, 2026 00:51
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

/* Process not found with lazy_mode=1 → EXIT_FAILURE */

P1 Badge Replace non-ASCII comment text with ASCII-only text

/workspace/cpulimit/AGENTS.md requires that only ASCII characters appear in code/comments, but this change introduces Unicode arrow characters () in tests/cpulimit_test.c comments (including this line and other newly added comments). This violates the project’s documented standards and can break tooling or checks that enforce source encoding/character-set constraints, so these comment markers should be replaced with ASCII equivalents (for example, ->).

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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.

2 participants