Skip to content

Commit 9972690

Browse files
pb8oroypat
authored andcommitted
tests: drop pandas dependency
Rewrite the only test that needs pandas. pandas is a heavy dependency that weighs in around 50MB. It also recently started printing a warning that in the future it will require pyarrow, which is another 40 MB. Pandas is great, however our usage of it is minimal. Size of devctr does not change much, but we avoid the warning, and not having to deal with pyarrow in the future. Example output: ``` MSR removed 0x13 before=0x0 MSR changed 0x179 before=0x20ffff after=0x20 MSR added 0x17 after=0x0 MSR added 0x11 after=0x25ba008 ``` Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent a27f8e2 commit 9972690

File tree

4 files changed

+35
-122
lines changed

4 files changed

+35
-122
lines changed

tests/integration_tests/functional/test_cpu_features.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# pylint: disable=too-many-lines
66

7+
import csv
78
import io
89
import os
910
import platform
@@ -14,7 +15,6 @@
1415
from difflib import unified_diff
1516
from pathlib import Path
1617

17-
import pandas as pd
1818
import pytest
1919

2020
import framework.utils_cpuid as cpuid_utils
@@ -30,6 +30,12 @@
3030
DATA_FILES = Path("./data/msr")
3131

3232

33+
def read_msr_csv(fd):
34+
"""Read a CSV of MSRs"""
35+
csvin = csv.DictReader(fd)
36+
return list(csvin)
37+
38+
3339
def clean_and_mkdir(dir_path):
3440
"""
3541
Create a clean directory
@@ -313,7 +319,7 @@ def test_cpu_rdmsr(
313319
assert stderr == ""
314320

315321
# Load results read from the microvm
316-
microvm_df = pd.read_csv(io.StringIO(stdout))
322+
guest_recs = read_msr_csv(io.StringIO(stdout))
317323

318324
# Load baseline
319325
host_cpu = global_props.cpu_codename
@@ -329,11 +335,9 @@ def test_cpu_rdmsr(
329335

330336
# Load baseline
331337
baseline_file_path = DATA_FILES / baseline_file_name
332-
# We can use the following line when regathering baselines.
333-
# microvm_df.to_csv(baseline_file_path, index=False, encoding="utf-8")
334-
baseline_df = pd.read_csv(baseline_file_path)
338+
baseline_recs = read_msr_csv(baseline_file_path.open())
335339

336-
check_msrs_are_equal(baseline_df, microvm_df)
340+
check_msrs_are_equal(baseline_recs, guest_recs)
337341

338342

339343
# These names need to be consistent across the two parts of the snapshot-restore test
@@ -441,29 +445,31 @@ def test_cpu_wrmsr_snapshot(
441445
snapshot.save_to(snapshot_artifacts_dir)
442446

443447

444-
def check_msrs_are_equal(before_df, after_df):
448+
def check_msrs_are_equal(before_recs, after_recs):
445449
"""
446450
Checks that reported MSRs and their values in the files are equal.
447451
"""
448452

453+
before = {x["MSR_ADDR"]: x["VALUE"] for x in before_recs}
454+
after = {x["MSR_ADDR"]: x["VALUE"] for x in after_recs}
449455
# We first want to see if the same set of MSRs are exposed in the microvm.
450-
# Drop the VALUE columns and compare the 2 dataframes.
451-
join = pd.merge(before_df, after_df, on="MSR_ADDR", how="outer", indicator=True)
452-
removed = join[join["_merge"] == "left_only"]
453-
added = join[join["_merge"] == "right_only"]
454-
455-
assert removed.empty, f"MSRs removed:\n{removed[['MSR_ADDR', 'VALUE_x']]}"
456-
assert added.empty, f"MSRs added:\n{added[['MSR_ADDR', 'VALUE_y']]}"
457-
458-
# Remove MSR that can change at runtime.
459-
before_df = before_df[~before_df["MSR_ADDR"].isin(MSR_EXCEPTION_LIST)]
460-
after_df = after_df[~after_df["MSR_ADDR"].isin(MSR_EXCEPTION_LIST)]
461-
462-
# Compare values
463-
val_diff = pd.concat(
464-
[before_df, after_df], keys=["before", "after"]
465-
).drop_duplicates(keep=False)
466-
assert val_diff.empty, f"\n {val_diff.to_string()}"
456+
all_msrs = set(before.keys()) | set(after.keys())
457+
458+
changes = 0
459+
for msr in all_msrs:
460+
if msr in before and msr not in after:
461+
print(f"MSR removed {msr} before={before[msr]}")
462+
changes += 1
463+
elif msr not in before and msr in after:
464+
print(f"MSR added {msr} after={after[msr]}")
465+
changes += 1
466+
elif msr in MSR_EXCEPTION_LIST:
467+
continue
468+
elif before[msr] != after[msr]:
469+
# Compare values
470+
print(f"MSR changed {msr} before={before[msr]} after={after[msr]}")
471+
changes += 1
472+
assert changes == 0
467473

468474

469475
@pytest.mark.skipif(
@@ -504,11 +510,12 @@ def test_cpu_wrmsr_restore(microvm_factory, msr_cpu_template, guest_kernel):
504510
# Dump MSR state to a file for further comparison
505511
msrs_after_fname = snapshot_artifacts_dir / shared_names["msrs_after_fname"]
506512
dump_msr_state_to_file(msrs_after_fname, vm.ssh, shared_names)
513+
msrs_before_fname = snapshot_artifacts_dir / shared_names["msrs_before_fname"]
507514

508515
# Compare the two lists of MSR values and assert they are equal
509-
before_df = pd.read_csv(snapshot_artifacts_dir / shared_names["msrs_before_fname"])
510-
after_df = pd.read_csv(snapshot_artifacts_dir / shared_names["msrs_after_fname"])
511-
check_msrs_are_equal(before_df, after_df)
516+
before_recs = read_msr_csv(msrs_before_fname.open())
517+
after_recs = read_msr_csv(msrs_after_fname.open())
518+
check_msrs_are_equal(before_recs, after_recs)
512519

513520

514521
def dump_cpuid_to_file(dump_fname, ssh_conn):

tools/devctr/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ RUN apt-get update \
5757
jq \
5858
less \
5959
libbfd-dev \
60-
# for pandas
61-
libbz2-dev \
6260
libdw-dev \
6361
# for aarch64, but can install in x86_64
6462
libfdt-dev \

tools/devctr/poetry.lock

Lines changed: 1 addition & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/devctr/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ mdformat-gfm = "^0.3.5"
1717
mdformat-footnote = "^0.1.1"
1818
mdformat-frontmatter = "^2.0.8"
1919
openapi-spec-validator = "^0.5.6"
20-
pandas = "^2.0.1"
2120
psutil = "^5.9.5"
2221
pylint = "^2.17.4"
2322
pytest = "^7.3.1"

0 commit comments

Comments
 (0)