Skip to content

Commit

Permalink
Add unittest for platform.machine().
Browse files Browse the repository at this point in the history
  • Loading branch information
hongtaozhang committed Nov 17, 2024
1 parent d5d95de commit 5c4e5d3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,18 @@ double BenchmarkNUMACopy(int src_node, int dst_node, Opts &opts) {
* @param opts A reference to an Opts object containing various options and configurations for the benchmark.
*/
double RunCPUCopyBenchmark(int src_node, int dst_node, Opts &opts) {
double max_time_ns = 0;

// Run warm up rounds
for (int i = 0; i < opts.num_warm_up; i++) {
BenchmarkNUMACopy(src_node, dst_node, opts);
}

double time_used_ns = 0;

for (int i = 0; i < opts.num_loops; i++) {
double time_used_ns = BenchmarkNUMACopy(src_node, dst_node, opts);
max_time_ns = std::max(max_time_ns, time_used_ns);
time_used_ns += BenchmarkNUMACopy(src_node, dst_node, opts);
}

return max_time_ns;
return time_used_ns / opts.num_loops;
}

int main(int argc, char **argv) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

"""Tests for cpu-memory-bw-latency benchmark."""

import os
import platform
import unittest

from tests.helper.testcase import BenchmarkTestCase
Expand Down Expand Up @@ -148,3 +150,43 @@ def test_cpu_mem_bw_latency_benchmark_result_parsing(self):
# Negative case - invalid raw output.
assert (benchmark._process_raw_result(0, 'Invalid raw output') is False)
assert (benchmark.return_code == ReturnCode.MICROBENCHMARK_RESULT_PARSING_FAILURE)

def test_preprocess_mlc(self):
"""Test _preprocess method for Intel MLC tool."""
benchmark_name = 'cpu-memory-bw-latency'
(benchmark_class, predefine_params) = BenchmarkRegistry._BenchmarkRegistry__select_benchmark(benchmark_name, Platform.CPU)
assert (benchmark_class)

benchmark = benchmark_class(benchmark_name, parameters='--tests bandwidth_matrix')
benchmark._args = benchmark._parser.parse_args(['--bin_dir', '/mock/bin/dir'])
benchmark._bin_name = 'mlc'
benchmark._commands = []

# Mock os.access to return True
os.access = lambda path, mode: True

ret = benchmark._preprocess()
assert (ret is True)
assert (benchmark.return_code == ReturnCode.SUCCESS)
assert (len(benchmark._commands) == 1)
assert ('mlc --bandwidth_matrix;' in benchmark._commands[0])

def test_preprocess_general(self):
"""Test _preprocess method for general CPU copy benchmark."""
benchmark_name = 'cpu-memory-bw-latency'
(benchmark_class, predefine_params) = BenchmarkRegistry._BenchmarkRegistry__select_benchmark(benchmark_name, Platform.CPU)
assert (benchmark_class)

benchmark = benchmark_class(benchmark_name, parameters='--size 1024 --num_warm_up 10 --num_loops 50 --check_data')
benchmark._args = benchmark._parser.parse_args(['--bin_dir', '/mock/bin/dir'])
benchmark._bin_name = 'cpu_copy'
benchmark._commands = []

# Mock platform.machine to return non-x86_64
platform.machine = lambda: 'arm64'

ret = benchmark._preprocess()
assert (ret is True)
assert (benchmark.return_code == ReturnCode.SUCCESS)
assert (len(benchmark._commands) == 1)
assert ('cpu_copy --size 1024 --num_warm_up 10 --num_loops 50 --check_data' in benchmark._commands[0])

0 comments on commit 5c4e5d3

Please sign in to comment.