-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
6 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,20 +1,61 @@ | ||
import sys | ||
import atheris | ||
from PSLab import interfaces, experiment, hardware | ||
import pslab | ||
|
||
def TestOneInput(data): | ||
|
||
def fuzz_i2c(data): | ||
fdp = atheris.FuzzedDataProvider(data) | ||
|
||
i2c = pslab.I2C() | ||
try: | ||
experiment.set_gain(fdp.ConsumeInt(4)) # Fuzz gain settings | ||
hardware.analog_read(fdp.ConsumeInt(4)) # Fuzz analog reading | ||
interfaces.send_data(fdp.ConsumeBytes(8)) # Fuzz data transmission | ||
address = fdp.ConsumeIntInRange(0, 127) # Valid 7-bit I2C addresses | ||
register = fdp.ConsumeIntInRange(0, 255) # Register range | ||
value = fdp.ConsumeIntInRange(0, 255) # Data to write | ||
|
||
i2c.read(address, register) | ||
|
||
i2c.write(address, register, value) | ||
except Exception: | ||
pass | ||
|
||
|
||
def fuzz_oscilloscope(data): | ||
fdp = atheris.FuzzedDataProvider(data) | ||
try: | ||
oscilloscope = pslab.instrument.Oscilloscope() | ||
|
||
# Fuzz parameters for capture | ||
channels = [fdp.ConsumeIntInRange(1, 4) for _ in range(2)] | ||
timegap = fdp.ConsumeFloat() # Time gap between captures | ||
|
||
oscilloscope.capture(channels=channels, timegap=timegap) | ||
except Exception: | ||
pass | ||
|
||
|
||
def fuzz_waveform_generator(data): | ||
fdp = atheris.FuzzedDataProvider(data) | ||
try: | ||
waveform_generator = pslab.waveform_generator.WaveformGenerator() | ||
|
||
frequency = fdp.ConsumeFloatInRange(1.0, 100000.0) # Frequency in Hz | ||
amplitude = fdp.ConsumeFloatInRange(0.1, 5.0) # Amplitude in volts | ||
waveform_type = fdp.ConsumeString(8) | ||
|
||
waveform_generator.generate(frequency=frequency, amplitude=amplitude, waveform_type=waveform_type) | ||
except Exception: | ||
pass | ||
|
||
|
||
def TestOneInput(data): | ||
fuzz_i2c(data) | ||
fuzz_oscilloscope(data) | ||
fuzz_waveform_generator(data) | ||
|
||
|
||
def main(): | ||
atheris.Setup(sys.argv, TestOneInput) | ||
atheris.Fuzz() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |