Skip to content

Commit 969377f

Browse files
zulinx86kalyazin
authored andcommitted
refactor(tool): Move template-related operations
Move files for template-related operations to `template/` directory to allow the helper tool have two types of operations (template-related and fingerprint-related operations). Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent f70cc8e commit 969377f

File tree

11 files changed

+20
-16
lines changed

11 files changed

+20
-16
lines changed

src/cpu-template-helper/src/main.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ use std::path::PathBuf;
77
use clap::{Parser, Subcommand};
88
use vmm::cpu_config::templates::{CustomCpuTemplate, GetCpuTemplate, GetCpuTemplateError};
99

10-
mod dump;
11-
mod strip;
10+
mod template;
1211
mod utils;
13-
mod verify;
1412

1513
const EXIT_CODE_ERROR: i32 = 1;
1614

@@ -25,9 +23,9 @@ enum Error {
2523
#[error("{0}")]
2624
Utils(#[from] utils::Error),
2725
#[error("{0}")]
28-
TemplateDump(#[from] dump::Error),
26+
TemplateDump(#[from] template::dump::Error),
2927
#[error("{0}")]
30-
TemplateVerify(#[from] verify::Error),
28+
TemplateVerify(#[from] template::verify::Error),
3129
}
3230

3331
type Result<T> = std::result::Result<T, Error>;
@@ -87,7 +85,7 @@ fn run(cli: Cli) -> Result<()> {
8785
let config = read_to_string(config)?;
8886
let (vmm, _) = utils::build_microvm_from_config(&config)?;
8987

90-
let cpu_config = dump::dump(vmm)?;
88+
let cpu_config = template::dump::dump(vmm)?;
9189

9290
let cpu_config_json = serde_json::to_string_pretty(&cpu_config)?;
9391
write(output, cpu_config_json)?;
@@ -100,7 +98,7 @@ fn run(cli: Cli) -> Result<()> {
10098
templates.push(template);
10199
}
102100

103-
let stripped_templates = strip::strip(templates);
101+
let stripped_templates = template::strip::strip(templates);
104102

105103
for (path, template) in paths.into_iter().zip(stripped_templates.into_iter()) {
106104
let path = utils::add_suffix(&path, &suffix);
@@ -117,9 +115,9 @@ fn run(cli: Cli) -> Result<()> {
117115
.cpu_template
118116
.get_cpu_template()?
119117
.into_owned();
120-
let cpu_config = dump::dump(vmm)?;
118+
let cpu_config = template::dump::dump(vmm)?;
121119

122-
verify::verify(cpu_template, cpu_config)?;
120+
template::verify::verify(cpu_template, cpu_config)?;
123121
}
124122
},
125123
Command::Fingerprint(_) => {}
@@ -267,7 +265,7 @@ mod tests {
267265
}
268266

269267
#[test]
270-
fn test_dump_command() {
268+
fn test_template_dump_command() {
271269
let kernel_image_path = kernel_image_path(None);
272270
let rootfs_file = TempFile::new().unwrap();
273271
let config_file = generate_config_file(
@@ -292,7 +290,7 @@ mod tests {
292290
}
293291

294292
#[test]
295-
fn test_strip_command() {
293+
fn test_template_strip_command() {
296294
let files = vec![generate_sample_modifiers(), generate_sample_modifiers()];
297295

298296
let mut args = vec!["cpu-template-helper", "template", "strip", "-p"];
@@ -307,7 +305,7 @@ mod tests {
307305
}
308306

309307
#[test]
310-
fn test_verify_command() {
308+
fn test_template_verify_command() {
311309
let kernel_image_path = kernel_image_path(None);
312310
let rootfs_file = TempFile::new().unwrap();
313311
let template_file = generate_sample_modifiers();
File renamed without changes.

src/cpu-template-helper/src/dump/mod.rs renamed to src/cpu-template-helper/src/template/dump/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use vmm::cpu_config::templates::CustomCpuTemplate;
1212
use vmm::{DumpCpuConfigError, Vmm};
1313

1414
#[cfg(target_arch = "aarch64")]
15-
use crate::dump::aarch64::config_to_template;
15+
use crate::template::dump::aarch64::config_to_template;
1616
#[cfg(target_arch = "x86_64")]
17-
use crate::dump::x86_64::config_to_template;
17+
use crate::template::dump::x86_64::config_to_template;
1818

1919
#[derive(Debug, thiserror::Error)]
2020
pub enum Error {
File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
pub mod dump;
5+
pub mod strip;
6+
pub mod verify;

src/cpu-template-helper/src/strip/aarch64.rs renamed to src/cpu-template-helper/src/template/strip/aarch64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use vmm::cpu_config::aarch64::custom_cpu_template::RegisterModifier;
55
use vmm::cpu_config::templates::CustomCpuTemplate;
66

7-
use crate::strip::strip_common;
7+
use crate::template::strip::strip_common;
88
use crate::utils::aarch64::RegModifierMap;
99

1010
#[allow(dead_code)]
File renamed without changes.

src/cpu-template-helper/src/strip/x86_64.rs renamed to src/cpu-template-helper/src/template/strip/x86_64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use vmm::cpu_config::templates::CustomCpuTemplate;
55
use vmm::cpu_config::x86_64::custom_cpu_template::{CpuidLeafModifier, RegisterModifier};
66

7-
use crate::strip::strip_common;
7+
use crate::template::strip::strip_common;
88
use crate::utils::x86_64::{CpuidModifierMap, MsrModifierMap};
99

1010
#[allow(dead_code)]
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)