Skip to content

Commit 89a6f3a

Browse files
committed
android tests.
1 parent 86d63cd commit 89a6f3a

File tree

8 files changed

+881
-4
lines changed

8 files changed

+881
-4
lines changed

.github/workflows/release.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,41 @@ on:
1212
type: string
1313

1414
jobs:
15+
android-tests:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
submodules: recursive
23+
24+
- name: Set up JDK 17
25+
uses: actions/setup-java@v4
26+
with:
27+
java-version: '17'
28+
distribution: 'temurin'
29+
30+
- name: Setup Android SDK
31+
uses: android-actions/setup-android@v3
32+
33+
- name: Grant execute permission for gradlew
34+
working-directory: android
35+
run: chmod +x gradlew
36+
37+
- name: Setup Gradle
38+
uses: gradle/actions/setup-gradle@v3
39+
40+
- name: Run unit tests
41+
working-directory: android
42+
run: ./gradlew test --stacktrace
43+
44+
- name: Build Android Test APK
45+
working-directory: android
46+
run: ./gradlew assembleDebugAndroidTest --stacktrace
47+
1548
build-aar:
49+
needs: [android-tests]
1650
runs-on: ubuntu-latest
1751

1852
steps:
@@ -86,7 +120,7 @@ jobs:
86120
path: release-artifacts/mldsa-xcframework.zip
87121

88122
create-release:
89-
needs: [build-aar, build-xcframework]
123+
needs: [android-tests, build-aar, build-xcframework]
90124
runs-on: ubuntu-latest
91125
permissions:
92126
contents: write

.github/workflows/test.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
android-tests:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
19+
20+
- name: Set up JDK 17
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: '17'
24+
distribution: 'temurin'
25+
26+
- name: Setup Android SDK
27+
uses: android-actions/setup-android@v3
28+
29+
- name: Grant execute permission for gradlew
30+
working-directory: android
31+
run: chmod +x gradlew
32+
33+
- name: Setup Gradle
34+
uses: gradle/actions/setup-gradle@v3
35+
36+
- name: Build native library
37+
working-directory: android
38+
run: ./gradlew :app:externalNativeBuildDebug
39+
40+
- name: Run unit tests
41+
working-directory: android
42+
run: ./gradlew test --stacktrace
43+
44+
- name: Build Android Test APK
45+
working-directory: android
46+
run: ./gradlew assembleDebugAndroidTest --stacktrace
47+
48+
- name: Run instrumented tests
49+
uses: reactivecircus/android-emulator-runner@v2
50+
with:
51+
api-level: 29
52+
target: default
53+
arch: x86_64
54+
profile: Nexus 6
55+
script: cd android && ./gradlew connectedDebugAndroidTest --stacktrace
56+
working-directory: ./
57+
58+
- name: Upload test results
59+
if: always()
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: test-results
63+
path: |
64+
android/app/build/reports/
65+
android/app/build/test-results/
66+
67+
- name: Publish test report
68+
if: always()
69+
uses: mikepenz/action-junit-report@v4
70+
with:
71+
report_paths: 'android/app/build/test-results/**/*.xml'
72+
check_name: Android Test Results

android/app/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ android {
3939

4040
dependencies {
4141
implementation 'androidx.appcompat:appcompat:1.6.1'
42+
43+
testImplementation 'junit:junit:4.13.2'
44+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
45+
androidTestImplementation 'androidx.test:runner:1.5.2'
46+
androidTestImplementation 'androidx.test:rules:1.5.0'
4247
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# ML-DSA Android Tests
2+
3+
This directory contains instrumented tests for the ML-DSA Android library.
4+
5+
## Test Files
6+
7+
### MLDSATest.java
8+
Comprehensive tests covering:
9+
- Key generation for all security levels (44, 65, 87)
10+
- Signing and verifying messages
11+
- Context strings
12+
- Invalid signatures and tampered data
13+
- Edge cases (empty messages, large messages, null inputs)
14+
- Multiple signatures and keypair independence
15+
16+
### MLDSASeedTest.java
17+
Focused tests for seed-based deterministic key generation:
18+
- Deterministic key generation with fixed seeds
19+
- Different seeds producing different keys
20+
- Edge cases (all-zero seed, all-ones seed)
21+
- Single-bit differences
22+
- Comparison with random key generation
23+
24+
## Running Tests
25+
26+
### Using Android Studio
27+
1. Open the project in Android Studio
28+
2. Connect an Android device or start an emulator
29+
3. Right-click on `androidTest` directory
30+
4. Select "Run 'All Tests'"
31+
32+
### Using Command Line
33+
34+
Run all instrumented tests:
35+
```bash
36+
cd /Users/alex/dev/ml_dsa/android
37+
./gradlew connectedAndroidTest
38+
```
39+
40+
Run specific test class:
41+
```bash
42+
./gradlew connectedAndroidTest --tests "com.mldsa.MLDSATest"
43+
./gradlew connectedAndroidTest --tests "com.mldsa.MLDSASeedTest"
44+
```
45+
46+
Run specific test method:
47+
```bash
48+
./gradlew connectedAndroidTest --tests "com.mldsa.MLDSATest.testSignAndVerify_SimpleMessage"
49+
```
50+
51+
### View Test Results
52+
53+
After running tests, view the HTML report at:
54+
```
55+
android/app/build/reports/androidTests/connected/index.html
56+
```
57+
58+
## Test Coverage
59+
60+
The test suite covers:
61+
62+
**Key Generation**
63+
- All security levels (ML-DSA-44, ML-DSA-65, ML-DSA-87)
64+
- Random key generation
65+
- Deterministic key generation with seed
66+
- Key size validation
67+
- Multiple independent keypairs
68+
69+
**Signing**
70+
- Simple messages
71+
- Empty messages
72+
- Large messages (1MB)
73+
- Messages with context strings
74+
- Multiple signatures for same message (randomized)
75+
76+
**Verification**
77+
- Valid signatures
78+
- Invalid/tampered signatures
79+
- Invalid/tampered messages
80+
- Wrong public keys
81+
- Context string validation
82+
83+
**Error Handling**
84+
- Null inputs
85+
- Invalid seed lengths
86+
- Invalid security levels
87+
88+
**Seed-Based Key Generation**
89+
- Deterministic generation
90+
- Reproducibility
91+
- Seed variations
92+
- Compatibility with signing/verification
93+
94+
## Requirements
95+
96+
- Android device or emulator (API level 21+)
97+
- Native library built for the target architecture
98+
- JUnit and AndroidX Test dependencies (automatically included)
99+
100+
## Notes
101+
102+
- These are **instrumented tests** that run on an Android device/emulator
103+
- Tests require the native ML-DSA library to be compiled and loaded
104+
- Each test is independent and can run in any order
105+
- Tests use secure practices (proper cleanup, error handling)

0 commit comments

Comments
 (0)