This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from olafurw/8-seu-bit-flip-simulator
issue #8 include seu simulation
- Loading branch information
Showing
13 changed files
with
393 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
.vscode | ||
toGround | ||
toGround/ | ||
opssat-doom.map | ||
src/build/ | ||
src/bin/ | ||
src/output/ | ||
output/ | ||
output/ | ||
lib/ | ||
deploy/ | ||
backup/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,36 @@ | ||
source /home/user/poky_sdk/environment-setup-cortexa8hf-neon-poky-linux-gnueabi; | ||
pushd src; | ||
make; | ||
popd; | ||
#!/bin/bash | ||
|
||
# default values | ||
STATIC_FLAG=NO | ||
CLEAN_FLAG=NO | ||
|
||
# delete backup folder if it exists because it contains the old build | ||
rm -rf backup | ||
|
||
# parse arguments | ||
for arg in "$@" | ||
do | ||
if [[ "$arg" == "static" ]]; then | ||
STATIC_FLAG=YES | ||
elif [[ "$arg" == "clean" ]]; then | ||
CLEAN_FLAG=YES | ||
fi | ||
done | ||
|
||
# source the environment setup script | ||
source /home/user/poky_sdk/environment-setup-cortexa8hf-neon-poky-linux-gnueabi | ||
|
||
# change directory to src | ||
pushd src | ||
|
||
# clean if requested | ||
if [[ "$CLEAN_FLAG" == "YES" ]]; then | ||
make clean | ||
fi | ||
|
||
# build the project | ||
make STATIC=$STATIC_FLAG | ||
|
||
# Return to the original directory | ||
popd | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
pushd src; | ||
make; | ||
popd; | ||
#!/bin/bash | ||
|
||
# default values | ||
STATIC_FLAG=NO | ||
CLEAN_FLAG=NO | ||
|
||
# delete backup folder if it exists because it contains the old build | ||
rm -rf backup | ||
|
||
# parse arguments | ||
for arg in "$@" | ||
do | ||
if [[ "$arg" == "static" ]]; then | ||
STATIC_FLAG=YES | ||
elif [[ "$arg" == "clean" ]]; then | ||
CLEAN_FLAG=YES | ||
fi | ||
done | ||
|
||
# change directory to src | ||
pushd src | ||
|
||
# clean if requested | ||
if [[ "$CLEAN_FLAG" == "YES" ]]; then | ||
make clean | ||
fi | ||
|
||
# build the project | ||
make STATIC=$STATIC_FLAG | ||
|
||
# Return to the original directory | ||
popd | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
=========================================== | ||
E1M1 / MAP01 | ||
=========================================== | ||
Time: 4:18 (par: 0:30) | ||
Player 1 (Green): | ||
Kills: 22 / 4 (550%) | ||
Items: 30 / 37 (81%) | ||
Secrets: 3 / 3 (100%) | ||
RNG Calls: 70148 | ||
=========================================== | ||
E1M1 / MAP01 | ||
=========================================== | ||
|
||
Time: 4:18 (par: 0:30) | ||
|
||
Player 1 (Green): | ||
Kills: 22 / 4 (550%) | ||
Items: 30 / 37 (81%) | ||
Secrets: 3 / 3 (100%) | ||
RNG Calls: 70148 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
=========================================== | ||
E1M1 / MAP01 | ||
=========================================== | ||
Time: 2:44 (par: 0:30) | ||
Player 1 (Green): | ||
Kills: 6 / 6 (100%) | ||
Items: 24 / 37 (64%) | ||
Secrets: 1 / 3 (33%) | ||
RNG Calls: 42696 | ||
=========================================== | ||
E1M1 / MAP01 | ||
=========================================== | ||
|
||
Time: 2:44 (par: 0:30) | ||
|
||
Player 1 (Green): | ||
Kills: 6 / 6 (100%) | ||
Items: 24 / 37 (64%) | ||
Secrets: 1 / 3 (33%) | ||
RNG Calls: 42696 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
=========================================== | ||
E1M1 / MAP01 | ||
=========================================== | ||
Time: 0:37 (par: 0:30) | ||
Player 1 (Green): | ||
Kills: 4 / 4 (100%) | ||
Items: 4 / 37 (10%) | ||
Secrets: 0 / 3 (0%) | ||
RNG Calls: 11492 | ||
=========================================== | ||
E1M1 / MAP01 | ||
=========================================== | ||
|
||
Time: 0:37 (par: 0:30) | ||
|
||
Player 1 (Green): | ||
Kills: 4 / 4 (100%) | ||
Items: 4 / 37 (10%) | ||
Secrets: 0 / 3 (0%) | ||
RNG Calls: 11492 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os | ||
import random | ||
import sys | ||
|
||
def flip_bit(byte, bit_position): | ||
"""Flip the specified bit in a byte""" | ||
return byte ^ (1 << bit_position) | ||
|
||
def simulate_seu(seu_target_file_path, seu_rate): | ||
"""Simulate SEU on a file given its path and SEU rate""" | ||
if not os.path.exists(seu_target_file_path): | ||
print("ERROR: SEU target file does not exist") | ||
sys.exit(1) | ||
|
||
# Read file into memory | ||
with open(seu_target_file_path, "rb") as file: | ||
data = bytearray(file.read()) | ||
|
||
total_bits = len(data) * 8 | ||
num_flips = int(total_bits * seu_rate) | ||
|
||
# Randomly select bits to flip | ||
for _ in range(num_flips): | ||
bit_to_flip = random.randint(0, total_bits - 1) | ||
byte_index = bit_to_flip // 8 | ||
bit_position = bit_to_flip % 8 | ||
data[byte_index] = flip_bit(data[byte_index], bit_position) | ||
|
||
# Write data back to file | ||
with open(seu_target_file_path, "wb") as file: | ||
file.write(data) | ||
|
||
# Check if the script has the necessary command-line arguments | ||
if len(sys.argv) != 3: | ||
print("Usage: python simulate_seu.py [seu_target_file_path] [seu_rate]") | ||
sys.exit(1) | ||
|
||
# Command-line arguments | ||
seu_target_file_path = sys.argv[1] | ||
try: | ||
seu_rate = float(sys.argv[2]) | ||
except ValueError: | ||
print("ERROR: SEU rate must be a float") | ||
sys.exit(1) | ||
|
||
# Simulate SEU on target file at given rate | ||
simulate_seu(seu_target_file_path, seu_rate) | ||
print("QAPLA': SEU simulation completed") | ||
sys.exit(0) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.