-
Notifications
You must be signed in to change notification settings - Fork 1
330 lines (273 loc) · 11.5 KB
/
Copy pathomnetpp_generation.yml
File metadata and controls
330 lines (273 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
name: OMNeT++ Code Generation Tests
on:
push:
branches: [ main ]
paths:
- 'lib/actor_simulation/omnetpp_generator.ex'
- 'examples/omnetpp_*/**'
- 'scripts/generate_omnetpp_examples.exs'
- '.github/workflows/omnetpp_generation.yml'
pull_request:
branches: [ main ]
jobs:
test-generation:
name: Test OMNeT++ Code Generation
runs-on: ubuntu-latest
strategy:
matrix:
# Reduced matrix for faster CI - only test latest versions
elixir: ['1.18']
otp: ['27']
# elixir: ['1.17', '1.18']
# otp: ['26', '27']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ matrix.elixir }}-${{ matrix.otp }}-
- name: Install dependencies
run: mix deps.get
- name: Compile
run: mix compile --warnings-as-errors
- name: Run generator tests
run: mix test test/omnetpp_generator_test.exs --trace
continue-on-error: true
- name: Generate OMNeT++ examples
run: mix run scripts/generate_omnetpp_examples.exs
- name: Validate generated code
run: mix run scripts/validate_omnetpp_output.exs
- name: Check file counts
run: |
echo "Checking generated files..."
# Check each example directory
for dir in examples/omnetpp_*; do
if [ -d "$dir" ]; then
echo "📁 $dir:"
echo " NED files: $(find $dir -name '*.ned' | wc -l)"
echo " Headers: $(find $dir -name '*.h' | wc -l)"
echo " Sources: $(find $dir -name '*.cc' | wc -l)"
echo " CMake: $([ -f $dir/CMakeLists.txt ] && echo '✓' || echo '✗')"
echo " Conan: $([ -f $dir/conanfile.txt ] && echo '✓' || echo '✗')"
echo " INI: $([ -f $dir/omnetpp.ini ] && echo '✓' || echo '✗')"
fi
done
- name: Verify no timestamps in code
run: |
echo "Checking for timestamps in generated code..."
# Search for date patterns in C++ and NED files
if grep -r -E '[0-9]{4}-[0-9]{2}-[0-9]{2}' examples/omnetpp_*/*.{h,cc,ned} 2>/dev/null; then
echo "❌ Found timestamps in generated files"
exit 1
else
echo "✅ No timestamps found"
fi
- name: Check C++ syntax validity
run: |
echo "Basic C++ syntax checks..."
for file in examples/omnetpp_*/*.cc; do
if [ -f "$file" ]; then
# Check for required patterns
if ! grep -q "Define_Module" "$file"; then
echo "❌ Missing Define_Module in $file"
exit 1
fi
module_name=$(basename "$file" .cc)
if ! grep -q "void ${module_name}::initialize()" "$file"; then
echo "❌ Missing initialize() in $file"
exit 1
fi
if ! grep -q "void ${module_name}::handleMessage" "$file"; then
echo "❌ Missing handleMessage() in $file"
exit 1
fi
fi
done
echo "✅ All C++ files have required methods"
- name: Validate NED syntax
run: |
echo "Validating NED file structure..."
for file in examples/omnetpp_*/*.ned; do
if [ -f "$file" ]; then
if ! grep -q "simple " "$file"; then
echo "❌ Missing simple module definitions in $file"
exit 1
fi
if ! grep -q "network " "$file"; then
echo "❌ Missing network definition in $file"
exit 1
fi
if ! grep -q "submodules:" "$file"; then
echo "❌ Missing submodules section in $file"
exit 1
fi
fi
done
echo "✅ All NED files have valid structure"
- name: Check CMake configuration
run: |
echo "Validating CMakeLists.txt files..."
for dir in examples/omnetpp_*; do
cmake_file="$dir/CMakeLists.txt"
if [ -f "$cmake_file" ]; then
if ! grep -q "cmake_minimum_required" "$cmake_file"; then
echo "❌ Missing cmake_minimum_required in $cmake_file"
exit 1
fi
if ! grep -q "OMNETPP_ROOT" "$cmake_file"; then
echo "❌ Missing OMNETPP_ROOT configuration in $cmake_file"
exit 1
fi
if ! grep -q "add_executable" "$cmake_file"; then
echo "❌ Missing add_executable in $cmake_file"
exit 1
fi
fi
done
echo "✅ All CMakeLists.txt files valid"
- name: Archive generated code
if: always()
uses: actions/upload-artifact@v4
with:
name: omnetpp-generated-code-elixir-${{ matrix.elixir }}-otp-${{ matrix.otp }}
path: |
examples/omnetpp_*/
!examples/omnetpp_*/*.o
!examples/omnetpp_*/build/
retention-days: 7
- name: Generate validation report
if: always()
run: |
echo "# OMNeT++ Generation Report" > validation_report.md
echo "" >> validation_report.md
echo "## Configuration" >> validation_report.md
echo "- Elixir: ${{ matrix.elixir }}" >> validation_report.md
echo "- OTP: ${{ matrix.otp }}" >> validation_report.md
echo "" >> validation_report.md
echo "## Generated Projects" >> validation_report.md
for dir in examples/omnetpp_*; do
if [ -d "$dir" ]; then
project=$(basename "$dir")
echo "### $project" >> validation_report.md
echo "- Files: $(find $dir -type f | wc -l)" >> validation_report.md
echo "- C++ sources: $(find $dir -name '*.cc' | wc -l)" >> validation_report.md
echo "- Headers: $(find $dir -name '*.h' | wc -l)" >> validation_report.md
echo "" >> validation_report.md
fi
done
- name: Upload validation report
if: always()
uses: actions/upload-artifact@v4
with:
name: validation-report-elixir-${{ matrix.elixir }}-otp-${{ matrix.otp }}
path: validation_report.md
retention-days: 30
verify-consistency:
name: Verify Generated Code Consistency
runs-on: ubuntu-latest
needs: test-generation
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Compare generated code across versions
run: |
echo "Comparing generated code consistency..."
# This ensures that different Elixir/OTP versions produce identical output
first_artifact=$(ls -d omnetpp-generated-code-* | head -1)
for artifact in omnetpp-generated-code-*; do
if [ "$artifact" != "$first_artifact" ]; then
echo "Comparing $first_artifact vs $artifact"
# Compare file counts
count1=$(find "$first_artifact" -name '*.cc' | wc -l)
count2=$(find "$artifact" -name '*.cc' | wc -l)
if [ "$count1" != "$count2" ]; then
echo "❌ File count mismatch: $count1 vs $count2"
exit 1
fi
fi
done
echo "✅ Generated code is consistent across versions"
compile-omnetpp-examples:
name: Compile & Test OMNeT++ Examples
runs-on: ubuntu-latest
needs: test-generation
strategy:
fail-fast: false
matrix:
# Test both regular and high-frequency examples
example: [omnetpp_burst, omnetpp_high_freq]
# example: [omnetpp_pubsub, omnetpp_pipeline, omnetpp_burst, omnetpp_loadbalanced]
steps:
- uses: actions/checkout@v4
- name: Download generated code artifacts
uses: actions/download-artifact@v4
with:
pattern: omnetpp-generated-code-*
merge-multiple: true
- name: Verify generated code exists
run: |
echo "Checking for generated OMNeT++ examples..."
ls -la examples/
if [ ! -d "examples/${{ matrix.example }}" ]; then
echo "ERROR: examples/${{ matrix.example }} not found"
exit 1
fi
echo "✅ Found examples/${{ matrix.example }}"
- name: Build and run simulation in OMNeT++ Docker container
run: |
docker run --rm \
-v "$(pwd):/workspace" \
-w /workspace/examples/${{ matrix.example }} \
-e OMNETPP_ROOT=/root/omnetpp \
ghcr.io/omnetpp/omnetpp:u24.04-6.2.0 \
/bin/bash -c "
set -e
echo 'Installing cmake...'
apt-get update -qq && apt-get install -y -qq cmake > /dev/null 2>&1
echo 'Configuring build environment...'
export PATH=\$OMNETPP_ROOT/bin:\$PATH
export LD_LIBRARY_PATH=\$OMNETPP_ROOT/lib:\$LD_LIBRARY_PATH
echo 'Building simulation...'
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release 2>&1 | grep -v 'CMake Warning' || true
cmake --build . --config Release
echo 'Verifying executable...'
EXECUTABLE=\$(find . -name '*.omnetpp.linux' -type f | head -1)
if [ -z \"\$EXECUTABLE\" ]; then
echo 'ERROR: Could not find OMNeT++ executable'
echo 'Files in build directory:'
ls -la
echo 'Files matching pattern:'
find . -name '*.omnetpp.*' -o -name '*omnetpp*'
exit 1
fi
echo \"✅ Found executable: \$EXECUTABLE\"
echo ''
echo '🚀 Running simulation...'
echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
cd ..
EXECUTABLE=\$(find build -name '*.omnetpp.linux' -type f | head -1)
cp \$EXECUTABLE .
EXECUTABLE_NAME=\$(basename \$EXECUTABLE)
./\$EXECUTABLE_NAME -f omnetpp.ini 2>&1 || EXIT_CODE=\$?
echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
if [ -z \"\$EXIT_CODE\" ] || [ \"\$EXIT_CODE\" -eq 0 ]; then
echo '✅ Simulation completed successfully!'
else
echo \"⚠️ Simulation exited with code: \$EXIT_CODE\"
exit \$EXIT_CODE
fi
"