Skip to content
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

feat(Fuzzer): new testing pattern FUZZ_STREAM #27

Merged
merged 12 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions .github/workflows/scenario-CoupledL2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,17 @@ jobs:
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
case:
- { id: l2l3, name: L2-L3 }
- { id: l2l3l2, name: L2-L3-L2 }
- { id: l2l3, name: L2-L3 , mode: FUZZ_ARI }
- { id: l2l3l2, name: L2-L3-L2, mode: FUZZ_ARI }
- { id: l2l3, name: L2-L3 , mode: FUZZ_STREAM }
- { id: l2l3l2, name: L2-L3-L2, mode: FUZZ_STREAM }
compiler:
- { cc: clang-16, cxx: clang++-16 }
- { cc: gcc, cxx: g++ }
exclude:
- { os: ubuntu-20.04, compiler: { cc: gcc, cxx: g++ } }
runs-on: ${{ matrix.os }}
name: Run | ${{ matrix.case.name }} | ${{ matrix.os }} | ${{ matrix.compiler.cc }}
name: Run | ${{ matrix.case.name }} | ${{ matrix.case.mode }} | ${{ matrix.os }} | ${{ matrix.compiler.cc }}
env:
CI_BUILD_STAGE_NAME: build
CI_RUNS_ON: ${{ matrix.os }}
Expand All @@ -200,7 +202,25 @@ jobs:

- name: Unpack artifact
working-directory: ${{ github.workspace }}
run: tar -zxf ${{ env.TLTEST_ARCHIVE }}
run: tar -zxvf ${{ env.TLTEST_ARCHIVE }}

- name: Setup mode configuration FUZZ_ARI
if: matrix.case.mode == 'FUZZ_ARI'
run: |
pwd
ls
sed -i 's/mode.0.*/mode.0 = FUZZ_ARI/g' ./configs/user.tltest.ini
sed -i 's/mode.1.*/mode.1 = FUZZ_ARI/g' ./configs/user.tltest.ini
cat ./configs/user.tltest.ini

- name: Setup mode configuration FUZZ_STREAM
if: matrix.case.mode == 'FUZZ_STREAM'
run: |
pwd
ls
sed -i 's/mode.0.*/mode.0 = FUZZ_STREAM/g' ./configs/user.tltest.ini
sed -i 's/mode.1.*/mode.1 = FUZZ_STREAM/g' ./configs/user.tltest.ini
cat ./configs/user.tltest.ini

- name: Run TL-Test-New for CoupledL2
run: |
Expand Down
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@ run: FORCE tltest-config-postbuild
@cp ./main/build/tltest.ini ./run/
@bash ./scripts/run_v3lt.sh

run_coupledL2-test-l2l3: FORCE tltest-config-coupledL2-test-l2l3
@rm -rf ./run
@mkdir ./run
@cp ./main/build/tltest_v3lt ./run/
@cp ./main/build/tltest_portgen.so ./run/
@cp ./main/build/tltest.ini ./run/
@bash ./scripts/run_v3lt.sh

run_coupledL2-test-l2l3l2: FORCE tltest-config-coupledL2-test-l2l3l2
@rm -rf ./run
@mkdir ./run
@cp ./main/build/tltest_v3lt ./run/
@cp ./main/build/tltest_portgen.so ./run/
@cp ./main/build/tltest.ini ./run/
@bash ./scripts/run_v3lt.sh


run-with-portgen: FORCE tltest-config-postbuild tltest-portgen
@rm -rf ./run
@mkdir ./run
Expand Down
10 changes: 9 additions & 1 deletion configs/user.tltest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
# core.tl_c
# core.tl_ul

[tltest.sequence]
mode.0 = FUZZ_ARI
mode.1 = FUZZ_ARI

[tltest.fuzzer]
seed = 1000
ari.interval = 10000
ari.target = 12
ari.target = 18
stream.interval = 100
stream.step = 0x40
stream.start = 0x00000000
stream.end = 0x0007FFFF

[tltest.logger]
verbose = 0
Expand Down
22 changes: 20 additions & 2 deletions main/Base/TLLocal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@

#include <cstdint>
#include <cstddef>
#include <unordered_map>


enum class TLSequenceMode {
PASSIVE = 0,
FUZZ_ARI,
FUZZ_STREAM,
FUZZ_COUNTER,
FUZZ_COUNTER_SYNC,
STREAM_COPY2,
STREAM_MULTI
};

struct TLLocalConfig {
public:
uint64_t seed;
Expand All @@ -15,8 +26,15 @@ struct TLLocalConfig {
unsigned int masterCountPerCoreTLC; // TL-C master count per core
unsigned int masterCountPerCoreTLUL; // TL-UL master count per core

uint64_t ariInterval; // Auto Range Iteration interval
uint64_t ariTarget; // Auto Range Iteration target
std::unordered_map<int, TLSequenceMode> sequenceModes; // Agent sequence modes

uint64_t fuzzARIInterval; // Fuzz Auto Range Iteration interval
uint64_t fuzzARITarget; // Fuzz Auto Range Iteration target

uint64_t fuzzStreamInterval; // Fuzz Stream interval
uint64_t fuzzStreamStep; // Fuzz Stream step
uint64_t fuzzStreamStart; // Fuzz Stream start address
uint64_t fuzzStreamEnd; // Fuzz Stream end address

public:
size_t GetAgentCount() const noexcept;
Expand Down
197 changes: 136 additions & 61 deletions main/Fuzzer/CFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
#include <algorithm>


static std::vector<CFuzzRange> RANGES = {
static std::vector<CFuzzRange> FUZZ_ARI_RANGES = {
{ .ordinal = 0, .maxTag = CFUZZER_RAND_RANGE_TAG, .maxSet = CFUZZER_RAND_RANGE_SET, .maxAlias = CFUZZER_RAND_RANGE_ALIAS },
{ .ordinal = 1, .maxTag = 0x1, .maxSet = 0x10, .maxAlias = 0x4 },
{ .ordinal = 2, .maxTag = 0x10, .maxSet = 0x1, .maxAlias = 0x4 }
};

static CFuzzRange FUZZ_STREAM_RANGE = {
.ordinal = 0, .maxTag = 0x10, .maxSet = 0x10, .maxAlias = CFUZZER_RAND_RANGE_ALIAS
};

static inline size_t fact(size_t n) noexcept
{
size_t r = 1;
Expand All @@ -28,56 +32,109 @@ static inline size_t fact(size_t n) noexcept
CFuzzer::CFuzzer(tl_agent::CAgent *cAgent) noexcept {
this->cAgent = cAgent;

this->rangeIndex = 0;
this->rangeIterationInterval = cAgent->config().ariInterval;
this->rangeIterationTarget = cAgent->config().ariTarget;

this->rangeIterationCount = 0;
this->rangeIterationTime = cAgent->config().ariInterval;
this->fuzzARIRangeIndex = 0;
this->fuzzARIRangeIterationInterval = cAgent->config().fuzzARIInterval;
this->fuzzARIRangeIterationTarget = cAgent->config().fuzzARITarget;

this->fuzzARIRangeIterationCount = 0;
this->fuzzARIRangeIterationTime = cAgent->config().fuzzARIInterval;

this->fuzzStreamOffset = 0;
this->fuzzStreamStepTime = cAgent->config().fuzzStreamStep;
this->fuzzStreamEnded = false;
this->fuzzStreamStep = cAgent->config().fuzzStreamStep;
this->fuzzStreamInterval = cAgent->config().fuzzStreamInterval;
this->fuzzStreamStart = cAgent->config().fuzzStreamStart;
this->fuzzStreamEnd = cAgent->config().fuzzStreamEnd;

decltype(cAgent->config().sequenceModes.end()) modeInMap;
if ((modeInMap = cAgent->config().sequenceModes.find(cAgent->sysId()))
!= cAgent->config().sequenceModes.end())
this->mode = modeInMap->second;
else
this->mode = TLSequenceMode::FUZZ_ARI;

if (this->mode == TLSequenceMode::FUZZ_ARI)
{
LogInfo(this->cAgent->cycle(), Append("CFuzzer [", cAgent->sysId(), "] in FUZZ_ARI mode").EndLine());

for (size_t i = 0; i < RANGES.size(); i++)
this->rangeOrdinal.push_back(i);
for (size_t i = 0; i < FUZZ_ARI_RANGES.size(); i++)
this->fuzzARIRangeOrdinal.push_back(i);

size_t loop = cAgent->sysSeed() % fact(rangeOrdinal.size());
for (size_t i = 0; i < loop; i++)
std::next_permutation(rangeOrdinal.begin(), rangeOrdinal.end());
size_t loop = cAgent->sysSeed() % fact(fuzzARIRangeOrdinal.size());
for (size_t i = 0; i < loop; i++)
std::next_permutation(fuzzARIRangeOrdinal.begin(), fuzzARIRangeOrdinal.end());

LogInfo(this->cAgent->cycle(), Append("Initial Fuzz Set: index = ", this->rangeIndex, ", permutation: "));
LogEx(
std::cout << "[ ";
for (size_t i = 0; i < rangeOrdinal.size(); i++)
std::cout << rangeOrdinal[i] << " ";
std::cout << "]";
);
LogEx(std::cout << std::endl);
LogInfo(this->cAgent->cycle(), Append("Initial Fuzz Set: index = ", this->fuzzARIRangeIndex, ", permutation: "));
LogEx(
std::cout << "[ ";
for (size_t i = 0; i < fuzzARIRangeOrdinal.size(); i++)
std::cout << fuzzARIRangeOrdinal[i] << " ";
std::cout << "]";
);
LogEx(std::cout << std::endl);
}
else if (this->mode == TLSequenceMode::FUZZ_STREAM)
{
LogInfo(this->cAgent->cycle(), Append("CFuzzer [", cAgent->sysId(), "] in FUZZ_STREAM mode").EndLine());
LogInfo(this->cAgent->cycle(), Append("CFuzzer [", cAgent->sysId(), "] stream steps ")
.Hex().ShowBase().Append(this->fuzzStreamStep).EndLine());
LogInfo(this->cAgent->cycle(), Append("CFuzzer [", cAgent->sysId(), "] stream starts at ")
.Hex().ShowBase().Append(this->fuzzStreamStart).EndLine());
LogInfo(this->cAgent->cycle(), Append("CFuzzer [", cAgent->sysId(), "] stream ends at ")
.Hex().ShowBase().Append(this->fuzzStreamEnd).EndLine());
}
}

void CFuzzer::randomTest(bool do_alias) {
paddr_t addr =
((CAGENT_RAND64(cAgent, "CFuzzer") % RANGES[rangeOrdinal[rangeIndex]].maxTag) << 13)
+ ((CAGENT_RAND64(cAgent, "CFuzzer") % RANGES[rangeOrdinal[rangeIndex]].maxSet) << 6); // Tag + Set + Offset
int alias = (do_alias) ? (CAGENT_RAND64(cAgent, "CFuzzer") % RANGES[rangeOrdinal[rangeIndex]].maxAlias) : 0;
if (CAGENT_RAND64(cAgent, "CFuzzer") % 2) {
if (CAGENT_RAND64(cAgent, "CFuzzer") % 3) {
if (CAGENT_RAND64(cAgent, "CFuzzer") % 2) {
cAgent->do_acquireBlock(addr, TLParamAcquire::NtoT, alias); // AcquireBlock NtoT
paddr_t addr;
int alias;
if (this->mode == TLSequenceMode::FUZZ_ARI || this->mode == TLSequenceMode::FUZZ_STREAM)
{
if (this->mode == TLSequenceMode::FUZZ_ARI)
{
// Tag + Set + Offset
addr = ((CAGENT_RAND64(cAgent, "CFuzzer") % FUZZ_ARI_RANGES[fuzzARIRangeOrdinal[fuzzARIRangeIndex]].maxTag) << 13)
+ ((CAGENT_RAND64(cAgent, "CFuzzer") % FUZZ_ARI_RANGES[fuzzARIRangeOrdinal[fuzzARIRangeIndex]].maxSet) << 6);
alias = (do_alias) ? (CAGENT_RAND64(cAgent, "CFuzzer") % FUZZ_ARI_RANGES[fuzzARIRangeOrdinal[fuzzARIRangeIndex]].maxAlias) : 0;
}
else
{
addr = ((CAGENT_RAND64(cAgent, "CFUZZER") % FUZZ_STREAM_RANGE.maxTag) << 13)
+ ((CAGENT_RAND64(cAgent, "CFUZZER") % FUZZ_STREAM_RANGE.maxSet) << 6)
+ this->fuzzStreamOffset
+ this->fuzzStreamStart;
alias = (do_alias) ? (CAGENT_RAND64(cAgent, "CFuzzer") % FUZZ_STREAM_RANGE.maxAlias) : 0;

if (addr >= this->fuzzStreamEnd)
{
this->fuzzStreamEnded = true;
return;
}
}

if (CAGENT_RAND64(cAgent, "CFuzzer") % 2) {
if (CAGENT_RAND64(cAgent, "CFuzzer") % 3) {
if (CAGENT_RAND64(cAgent, "CFuzzer") % 2) {
cAgent->do_acquireBlock(addr, TLParamAcquire::NtoT, alias); // AcquireBlock NtoT
} else {
cAgent->do_acquireBlock(addr, TLParamAcquire::NtoB, alias); // AcquireBlock NtoB
}
} else {
cAgent->do_acquireBlock(addr, TLParamAcquire::NtoB, alias); // AcquireBlock NtoB
cAgent->do_acquirePerm(addr, TLParamAcquire::NtoT, alias); // AcquirePerm
}
} else {
cAgent->do_acquirePerm(addr, TLParamAcquire::NtoT, alias); // AcquirePerm
}
} else {
/*
uint8_t* putdata = new uint8_t[DATASIZE];
for (int i = 0; i < DATASIZE; i++) {
putdata[i] = (uint8_t)CAGENT_RAND64(cAgent, "CFuzzer");
/*
uint8_t* putdata = new uint8_t[DATASIZE];
for (int i = 0; i < DATASIZE; i++) {
putdata[i] = (uint8_t)CAGENT_RAND64(cAgent, "CFuzzer");
}
cAgent->do_releaseData(addr, tl_agent::TtoN, putdata); // ReleaseData
*/
cAgent->do_releaseDataAuto(addr, alias,
CAGENT_RAND64(cAgent, "CFuzzer") & 0x1,
CAGENT_RAND64(cAgent, "CFuzzer") & 0x1); // feel free to releaseData according to its priv
}
cAgent->do_releaseData(addr, tl_agent::TtoN, putdata); // ReleaseData
*/
cAgent->do_releaseDataAuto(addr, alias,
CAGENT_RAND64(cAgent, "CFuzzer") & 0x1,
CAGENT_RAND64(cAgent, "CFuzzer") & 0x1); // feel free to releaseData according to its priv
}
}

Expand All @@ -98,34 +155,52 @@ void CFuzzer::caseTest() {
}

void CFuzzer::tick() {
this->randomTest(true);
// this->caseTest();

if (this->cAgent->cycle() >= this->rangeIterationTime)
if (this->mode == TLSequenceMode::FUZZ_ARI)
{
this->rangeIterationTime += this->rangeIterationInterval;
this->rangeIndex++;
this->randomTest(true);

if (this->rangeIndex == rangeOrdinal.size())
if (this->cAgent->cycle() >= this->fuzzARIRangeIterationTime)
{
this->rangeIndex = 0;
this->rangeIterationCount++;
this->fuzzARIRangeIterationTime += this->fuzzARIRangeIterationInterval;
this->fuzzARIRangeIndex++;

if (this->fuzzARIRangeIndex == fuzzARIRangeOrdinal.size())
{
this->fuzzARIRangeIndex = 0;
this->fuzzARIRangeIterationCount++;

std::next_permutation(fuzzARIRangeOrdinal.begin(), fuzzARIRangeOrdinal.end());
}

std::next_permutation(rangeOrdinal.begin(), rangeOrdinal.end());
LogInfo(this->cAgent->cycle(), Append("Fuzz Set switched: index = ", this->fuzzARIRangeIndex, ", permutation: "));
LogEx(
std::cout << "[ ";
for (size_t i = 0; i < fuzzARIRangeOrdinal.size(); i++)
std::cout << fuzzARIRangeOrdinal[i] << " ";
std::cout << "]";
);
LogEx(std::cout << std::endl);
}

LogInfo(this->cAgent->cycle(), Append("Fuzz Set switched: index = ", this->rangeIndex, ", permutation: "));
LogEx(
std::cout << "[ ";
for (size_t i = 0; i < rangeOrdinal.size(); i++)
std::cout << rangeOrdinal[i] << " ";
std::cout << "]";
);
LogEx(std::cout << std::endl);
if (this->fuzzARIRangeIterationCount == this->fuzzARIRangeIterationTarget)
{
TLSystemFinishEvent().Fire();
}
}

if (this->rangeIterationCount == this->rangeIterationTarget)
else if (this->mode == TLSequenceMode::FUZZ_STREAM)
{
TLSystemFinishEvent().Fire();
this->randomTest(true);

if (this->cAgent->cycle() >= this->fuzzStreamStepTime)
{
this->fuzzStreamStepTime += this->fuzzStreamInterval;
this->fuzzStreamOffset += this->fuzzStreamStep;
}

if (this->fuzzStreamEnded)
{
TLSystemFinishEvent().Fire();
}
}
}
Loading
Loading