Skip to content

Commit bd8c99f

Browse files
committed
ci(ut): add ut for test coverage
Signed-off-by: imeoer <yansong.ys@antgroup.com>
1 parent 821a512 commit bd8c99f

78 files changed

Lines changed: 3195 additions & 205 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/smoke.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,96 @@ jobs:
301301
path: |
302302
codecov.json
303303
304+
nydus-integration-test-coverage:
305+
if: github.event_name == 'pull_request'
306+
needs: [contrib-build]
307+
runs-on: ubuntu-latest
308+
env:
309+
CARGO_TERM_COLOR: always
310+
steps:
311+
- name: Checkout
312+
uses: actions/checkout@v6
313+
- name: Rust Cache
314+
uses: Swatinem/rust-cache@v2
315+
with:
316+
cache-on-failure: true
317+
shared-key: Linux-cargo-amd64-coverage
318+
save-if: ${{ github.ref == 'refs/heads/master' }}
319+
- name: Install cargo-llvm-cov
320+
uses: taiki-e/install-action@cargo-llvm-cov
321+
- name: Setup Golang
322+
uses: actions/setup-go@v5
323+
with:
324+
go-version-file: 'go.work'
325+
cache-dependency-path: "**/*.sum"
326+
- name: Download Nydusify
327+
uses: actions/download-artifact@v7
328+
with:
329+
name: nydusify-artifact
330+
path: contrib/nydusify/cmd
331+
- name: Fscache Setup
332+
run: sudo bash misc/fscache/setup.sh
333+
- name: Prepare Older Binaries
334+
run: |
335+
export NYDUS_STABLE_VERSION=$(curl https://api.github.com/repos/Dragonflyoss/nydus/releases/latest | jq -r '.tag_name')
336+
337+
versions=(v0.1.0 ${NYDUS_STABLE_VERSION})
338+
version_archs=(v0.1.0-x86_64 ${NYDUS_STABLE_VERSION}-linux-amd64)
339+
for i in ${!versions[@]}; do
340+
version=${versions[$i]}
341+
version_arch=${version_archs[$i]}
342+
343+
wget -q https://github.com/dragonflyoss/nydus/releases/download/$version/nydus-static-$version_arch.tgz
344+
sudo mkdir -p nydus-$version /usr/bin/nydus-$version
345+
sudo tar xzf nydus-static-$version_arch.tgz -C nydus-$version
346+
sudo cp -r nydus-$version/nydus-static/* /usr/bin/nydus-$version/
347+
done
348+
- name: Free Disk Space
349+
uses: jlumbroso/free-disk-space@main
350+
with:
351+
tool-cache: false
352+
android: true
353+
dotnet: true
354+
haskell: true
355+
large-packages: true
356+
docker-images: true
357+
swap-storage: true
358+
- name: Generate integration coverage
359+
shell: bash
360+
run: |
361+
source <(cargo llvm-cov show-env --sh)
362+
cargo llvm-cov clean --workspace
363+
cargo build --release --features=virtiofs --bins
364+
365+
sudo mkdir -p /usr/bin/nydus-latest /home/runner/work/workdir
366+
sudo install -D -m 755 contrib/nydusify/cmd/nydusify /usr/bin/nydus-latest
367+
sudo install -D -m 755 target/release/nydusd target/release/nydus-image /usr/bin/nydus-latest
368+
sudo bash misc/prepare.sh
369+
370+
export NYDUS_STABLE_VERSION=$(curl https://api.github.com/repos/Dragonflyoss/nydus/releases/latest | jq -r '.tag_name')
371+
export NYDUS_STABLE_VERSION_EXPORT="${NYDUS_STABLE_VERSION//./_}"
372+
373+
versions=(v0.1.0 ${NYDUS_STABLE_VERSION} latest)
374+
version_exports=(v0_1_0 ${NYDUS_STABLE_VERSION_EXPORT} latest)
375+
for i in ${!version_exports[@]}; do
376+
version=${versions[$i]}
377+
version_export=${version_exports[$i]}
378+
export NYDUS_BUILDER_$version_export=/usr/bin/nydus-$version/nydus-image
379+
export NYDUS_NYDUSD_$version_export=/usr/bin/nydus-$version/nydusd
380+
export NYDUS_NYDUSIFY_$version_export=/usr/bin/nydus-$version/nydusify
381+
done
382+
383+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/bin v2.1.6
384+
sudo -E make smoke-only
385+
386+
cargo llvm-cov report --release --codecov --output-path smoke-codecov.json
387+
- name: Upload integration coverage file
388+
uses: actions/upload-artifact@v6
389+
with:
390+
name: nydus-integration-test-coverage-artifact
391+
path: |
392+
smoke-codecov.json
393+
304394
upload-coverage-to-codecov:
305395
runs-on: ubuntu-latest
306396
needs: [contrib-unit-test-coverage, nydus-unit-test-coverage]
@@ -323,6 +413,25 @@ jobs:
323413
verbose: true
324414
fail_ci_if_error: true
325415

416+
upload-integration-coverage-to-codecov:
417+
if: github.event_name == 'pull_request'
418+
runs-on: ubuntu-latest
419+
needs: [nydus-integration-test-coverage]
420+
steps:
421+
- uses: actions/checkout@v6
422+
- name: Download nydus integration coverage file
423+
uses: actions/download-artifact@v7
424+
with:
425+
name: nydus-integration-test-coverage-artifact
426+
- name: Upload integration coverage to Codecov
427+
uses: codecov/codecov-action@v5
428+
env:
429+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
430+
with:
431+
files: ./smoke-codecov.json
432+
verbose: true
433+
fail_ci_if_error: true
434+
326435
nydus-cargo-deny:
327436
name: cargo-deny
328437
runs-on: ubuntu-latest

api/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2176,7 +2176,7 @@ mod tests {
21762176
}
21772177
}"#;
21782178

2179-
let mut rafs_config = ConfigV2::from_str(&config).unwrap();
2179+
let mut rafs_config = ConfigV2::from_str(config).unwrap();
21802180
let test_auth = "test_auth".to_string();
21812181

21822182
rafs_config.update_registry_auth_info(&Some(test_auth.clone()));

builder/src/core/blob.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,8 @@ impl Blob {
106106
if let Some((_, blob_ctx)) = blob_mgr.get_current_blob() {
107107
let mut batch = batch.lock().unwrap();
108108
if !batch.chunk_data_buf_is_empty() {
109-
let (_, compressed_size, _) = Node::write_chunk_data(
110-
&ctx,
111-
blob_ctx,
112-
blob_writer,
113-
batch.chunk_data_buf(),
114-
)?;
109+
let (_, compressed_size, _) =
110+
Node::write_chunk_data(ctx, blob_ctx, blob_writer, batch.chunk_data_buf())?;
115111
batch.add_context(compressed_size);
116112
batch.clear_chunk_data_buf();
117113
}
@@ -226,7 +222,7 @@ impl Blob {
226222
header.set_ci_entries(blob_meta_info.len() as u32);
227223
header.set_ci_compressed_offset(compressed_offset);
228224
header.set_ci_compressed_size(compressed_size as u64);
229-
header.set_ci_uncompressed_size(uncompressed_size as u64);
225+
header.set_ci_uncompressed_size(uncompressed_size);
230226
header.set_aligned(true);
231227
match blob_meta_info {
232228
BlobMetaChunkArray::V1(_) => header.set_chunk_info_v2(false),
@@ -280,7 +276,7 @@ impl Blob {
280276
hasher.digest_finalize(),
281277
compressed_offset,
282278
compressed_size as u64,
283-
uncompressed_size as u64,
279+
uncompressed_size,
284280
)?;
285281

286282
let mut hasher = RafsDigest::hasher(digest::Algorithm::Sha256);

builder/src/core/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl BlobCacheGenerator {
452452

453453
guard.seek(std::io::SeekFrom::Start(chunk_info.uncompressed_offset()))?;
454454
guard
455-
.write_all(&chunk_data)
455+
.write_all(chunk_data)
456456
.context("failed to write blob cache")?;
457457
Ok(())
458458
}
@@ -1002,7 +1002,7 @@ impl BlobManager {
10021002
self.add_blob(blob_ctx);
10031003
}
10041004
}
1005-
Ok((blob_idx as u32, &mut self.blobs[blob_idx as usize]))
1005+
Ok((blob_idx as u32, &mut self.blobs[blob_idx]))
10061006
}
10071007

10081008
/// Get the current blob object.

builder/src/core/node.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,9 @@ impl Node {
302302
external_blob_ctx.blob_id = external_blob_id.to_string();
303303
external_blob_ctx.compressed_blob_size = external_compressed_size;
304304
external_blob_ctx.uncompressed_blob_size = external_compressed_size;
305-
let chunk_count = self
306-
.chunk_count(external_chunk_size as u64)
307-
.with_context(|| {
308-
format!("failed to get chunk count for {}", self.path().display())
309-
})?;
305+
let chunk_count = self.chunk_count(external_chunk_size).with_context(|| {
306+
format!("failed to get chunk count for {}", self.path().display())
307+
})?;
310308
self.inode.set_child_count(chunk_count);
311309

312310
info!(
@@ -320,7 +318,7 @@ impl Node {
320318
);
321319
for i in 0..self.inode.child_count() {
322320
let mut chunk = self.inode.create_chunk();
323-
let file_offset = i as u64 * external_chunk_size as u64;
321+
let file_offset = i as u64 * external_chunk_size;
324322
let compressed_size = if i == self.inode.child_count() - 1 {
325323
self.inode.size() - (external_chunk_size * i as u64)
326324
} else {

builder/src/core/overlay.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,14 @@ mod tests {
229229
assert!(matches!(spec, WhiteoutSpec::Oci));
230230

231231
assert!(WhiteoutSpec::from_str("oci").is_ok());
232+
assert!(WhiteoutSpec::from_str("OCI").is_ok());
232233
assert!(WhiteoutSpec::from_str("overlayfs").is_ok());
233234
assert!(WhiteoutSpec::from_str("none").is_ok());
234235
assert!(WhiteoutSpec::from_str("foo").is_err());
236+
237+
assert_eq!(WhiteoutSpec::Oci.to_string(), "oci");
238+
assert_eq!(WhiteoutSpec::Overlayfs.to_string(), "overlayfs");
239+
assert_eq!(WhiteoutSpec::None.to_string(), "none");
235240
}
236241

237242
#[test]
@@ -255,6 +260,10 @@ mod tests {
255260
assert!(t1.is_lower_layer());
256261
assert!(!t2.is_lower_layer());
257262
assert!(!t3.is_lower_layer());
263+
264+
assert_eq!(t1.to_string(), "LOWER");
265+
assert_eq!(t2.to_string(), "ADDED");
266+
assert_eq!(t3.to_string(), "MODIFIED");
258267
}
259268

260269
#[test]

builder/src/core/v6.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl Node {
7171
if self.is_dir() {
7272
self.v6_dump_dir(ctx, f_bootstrap, meta_addr, meta_offset, &mut inode)?;
7373
} else if self.is_reg() {
74-
self.v6_dump_file(ctx, f_bootstrap, chunk_cache, &mut inode, &blobs)?;
74+
self.v6_dump_file(ctx, f_bootstrap, chunk_cache, &mut inode, blobs)?;
7575
} else if self.is_symlink() {
7676
self.v6_dump_symlink(ctx, f_bootstrap, &mut inode)?;
7777
} else {
@@ -171,7 +171,7 @@ impl Node {
171171
let len = c.len() + size_of::<RafsV6Dirent>();
172172
// erofs disk format requires dirent to be aligned to block size.
173173
if (d_size % block_size) + len as u64 > block_size {
174-
d_size = round_up(d_size as u64, block_size);
174+
d_size = round_up(d_size, block_size);
175175
}
176176
d_size += len as u64;
177177
}
@@ -185,7 +185,7 @@ impl Node {
185185
let len = child.name().len() + size_of::<RafsV6Dirent>();
186186
// erofs disk format requires dirent to be aligned to block size.
187187
if (d_size % block_size) + len as u64 > block_size {
188-
d_size = round_up(d_size as u64, block_size);
188+
d_size = round_up(d_size, block_size);
189189
}
190190
d_size += len as u64;
191191
}
@@ -380,7 +380,7 @@ impl Node {
380380
}
381381

382382
f_bootstrap
383-
.seek(SeekFrom::Start(dirent_off as u64))
383+
.seek(SeekFrom::Start(dirent_off))
384384
.context("failed seek file position for writing dirent")?;
385385
f_bootstrap
386386
.write(dir_data.as_slice())
@@ -736,7 +736,7 @@ impl Bootstrap {
736736
ext_sb.set_prefetch_table_size(prefetch_table_size);
737737
bootstrap_ctx
738738
.writer
739-
.seek_offset(prefetch_table_offset as u64)
739+
.seek_offset(prefetch_table_offset)
740740
.context("failed seek prefetch table offset")?;
741741
pt.store(bootstrap_ctx.writer.as_mut()).unwrap();
742742
}

builder/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,18 +379,18 @@ mod tests {
379379
let builder = TarBuilder::new(true, 0, RafsVersion::V6);
380380

381381
let path = Path::new("/stargz.index.json");
382-
assert!(builder.is_stargz_special_files(&path));
382+
assert!(builder.is_stargz_special_files(path));
383383
let path = Path::new("/.prefetch.landmark");
384-
assert!(builder.is_stargz_special_files(&path));
384+
assert!(builder.is_stargz_special_files(path));
385385
let path = Path::new("/.no.prefetch.landmark");
386-
assert!(builder.is_stargz_special_files(&path));
386+
assert!(builder.is_stargz_special_files(path));
387387

388388
let path = Path::new("/no.prefetch.landmark");
389-
assert!(!builder.is_stargz_special_files(&path));
389+
assert!(!builder.is_stargz_special_files(path));
390390
let path = Path::new("/prefetch.landmark");
391-
assert!(!builder.is_stargz_special_files(&path));
391+
assert!(!builder.is_stargz_special_files(path));
392392
let path = Path::new("/tar.index.json");
393-
assert!(!builder.is_stargz_special_files(&path));
393+
assert!(!builder.is_stargz_special_files(path));
394394
}
395395

396396
#[test]

builder/src/merge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl Merger {
140140
.context(format!("load parent bootstrap {:?}", parent_bootstrap_path))?;
141141
let blobs = rs.superblock.get_blob_infos();
142142
for blob in &blobs {
143-
let blob_ctx = BlobContext::from(ctx, &blob, ChunkSource::Parent)?;
143+
let blob_ctx = BlobContext::from(ctx, blob, ChunkSource::Parent)?;
144144
blob_idx_map.insert(blob_ctx.blob_id.clone(), blob_mgr.len());
145145
blob_mgr.add_blob(blob_ctx);
146146
}
@@ -188,7 +188,7 @@ impl Merger {
188188
let mut parent_blob_added = false;
189189
let blobs = &rs.superblock.get_blob_infos();
190190
for blob in blobs {
191-
let mut blob_ctx = BlobContext::from(ctx, &blob, ChunkSource::Parent)?;
191+
let mut blob_ctx = BlobContext::from(ctx, blob, ChunkSource::Parent)?;
192192
if let Some(chunk_size) = chunk_size {
193193
ensure!(
194194
chunk_size == blob_ctx.chunk_size,

builder/src/optimize_prefetch.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl OptimizePrefetch {
108108
RafsBlobTable::V6(table) => table.get_all().len(),
109109
};
110110
let mut blob_state =
111-
PrefetchBlobState::new(&ctx, blob_layer_num as u32, &output_blob_dir_path)?;
111+
PrefetchBlobState::new(ctx, blob_layer_num as u32, &output_blob_dir_path)?;
112112
let mut batch = BatchContextGenerator::new(0)?;
113113
for node in prefetch_files.clone() {
114114
Self::process_prefetch_node(
@@ -146,7 +146,7 @@ impl OptimizePrefetch {
146146
// carefully address hardlink
147147
for node in prefetch_files.clone() {
148148
let file = &node.path;
149-
if tree.get_node(&file).is_none() {
149+
if tree.get_node(file).is_none() {
150150
warn!(
151151
"prefetch file {} is skipped, no need to fixing hardlink",
152152
file.display()
@@ -155,7 +155,7 @@ impl OptimizePrefetch {
155155
}
156156

157157
let tree_node = tree
158-
.get_node(&file)
158+
.get_node(file)
159159
.ok_or(anyhow!("failed to get node"))?
160160
.node
161161
.as_ref();
@@ -182,7 +182,7 @@ impl OptimizePrefetch {
182182
RafsBlobTable::V6(table) => table.get_all(),
183183
};
184184
blob_mgr.extend_from_blob_table(ctx, blob_info)?;
185-
let blob_table_withprefetch = blob_mgr.to_blob_table(&ctx)?;
185+
let blob_table_withprefetch = blob_mgr.to_blob_table(ctx)?;
186186

187187
bootstrap.dump(
188188
ctx,
@@ -210,10 +210,10 @@ impl OptimizePrefetch {
210210
let mut blob_mgr = BlobManager::new(ctx.digester, false);
211211
blob_mgr.add_blob(blob_state.blob_ctx.clone());
212212
blob_mgr.set_current_blob_index(0);
213-
Blob::finalize_blob_data(&ctx, &mut blob_mgr, blob_state.blob_writer.as_mut())?;
213+
Blob::finalize_blob_data(ctx, &mut blob_mgr, blob_state.blob_writer.as_mut())?;
214214
if let RafsBlobTable::V6(_) = blob_table {
215215
if let Some((_, blob_ctx)) = blob_mgr.get_current_blob() {
216-
Blob::dump_meta_data(&ctx, blob_ctx, blob_state.blob_writer.as_mut()).unwrap();
216+
Blob::dump_meta_data(ctx, blob_ctx, blob_state.blob_writer.as_mut()).unwrap();
217217
};
218218
}
219219
ctx.blob_id = String::from("");
@@ -340,7 +340,7 @@ impl OptimizePrefetch {
340340
(blob_info.meta_ci_uncompressed_size()
341341
+ size_of::<BlobChunkInfoV2Ondisk>() as u64) as usize,
342342
);
343-
blob_ctx.add_chunk_meta_info(&inner, Some(info))?;
343+
blob_ctx.add_chunk_meta_info(inner, Some(info))?;
344344
}
345345
blob_ctx.compressed_blob_size += inner.compressed_size() as u64;
346346
blob_ctx.uncompressed_blob_size += aligned_d_size;

0 commit comments

Comments
 (0)