Skip to content

Added tests for edge cases #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: code-analysis
Choose a base branch
from
Open

Added tests for edge cases #179

wants to merge 2 commits into from

Conversation

peter-lawrey
Copy link
Member

@peter-lawrey peter-lawrey commented May 23, 2025

This patch adds 10 new JUnit tests (+3 CPU-layout fixtures) to harden the Java Thread Affinity project against edge cases.
It touches only the src/test tree – no production code is modified.

Test class Purpose
AffinityLockDumpLocksTest Verifies dumpLocks() lists all threads currently holding locks.
AffinityLockReleaseTest Ensures AffinityLock.release() restores the mask to BASE_AFFINITY.
AffinityResetToBaseAffinityTest Confirms Affinity.resetToBaseAffinity() resets the calling thread correctly.
AffinityThreadFactoryTest Checks that threads created by AffinityThreadFactory each bind to a distinct CPU (Linux only).
CpuInfoLayoutMappingTest Regression test for parsing /proc/cpuinfo into a correct logical-to-physical map.
UtilitiesTest Edge-case conversions for Utilities.toHexString and toBinaryString with high/empty bits.
VanillaCpuLayoutPropertiesParseTest Parses sample .properties layouts (i3, dual-Xeon, dual-E5405) and validates counts.

(Three helper classes extend BaseAffinityTest to reuse temporary-dir handling and Linux checks.)

Improves confidence in affinity-lock lifecycle, CPU-layout parsing, and utility helpers.

@peter-lawrey peter-lawrey requested a review from tgd May 23, 2025 11:05

import static org.junit.Assert.assertEquals;

public class VanillaCpuLayoutPropertiesParseTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should cover Ryzen and Epyc here

Copy link
Member Author

Choose a reason for hiding this comment

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

The CPU model here is illustrative, we could change the names of the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, the properties files are cpuinfo dumps IIRC - it would prove that the parser handles the latest layouts (I assume it should just work)

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