1f08c3bdfSopenharmony_ci#!/bin/sh
2f08c3bdfSopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later
3f08c3bdfSopenharmony_ci# Copyright (c) Linux Test Project, 2003-2021
4f08c3bdfSopenharmony_ci#
5f08c3bdfSopenharmony_ci# Test basic functionality of cpio command
6f08c3bdfSopenharmony_ci
7f08c3bdfSopenharmony_ciTST_TESTFUNC=cpio_test
8f08c3bdfSopenharmony_ciTST_NEEDS_TMPDIR=1
9f08c3bdfSopenharmony_ciTST_NEEDS_CMDS="cpio"
10f08c3bdfSopenharmony_ciTST_SETUP="setup"
11f08c3bdfSopenharmony_ci
12f08c3bdfSopenharmony_cisetup()
13f08c3bdfSopenharmony_ci{
14f08c3bdfSopenharmony_ci	if ! cpio --help 2>&1 | grep -q -- '-o.*Create'; then
15f08c3bdfSopenharmony_ci		tst_brk TCONF "-o flag not supported"
16f08c3bdfSopenharmony_ci	fi
17f08c3bdfSopenharmony_ci
18f08c3bdfSopenharmony_ci	ARCHIVE_FORMAT=
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_ci	if cpio 2>&1 | grep -q 'BusyBox'; then
21f08c3bdfSopenharmony_ci		ARCHIVE_FORMAT="-H newc"
22f08c3bdfSopenharmony_ci	fi
23f08c3bdfSopenharmony_ci}
24f08c3bdfSopenharmony_ci
25f08c3bdfSopenharmony_cicpio_test()
26f08c3bdfSopenharmony_ci{
27f08c3bdfSopenharmony_ci	ROD mkdir "dir"
28f08c3bdfSopenharmony_ci	for i in a b c d e f g h i j k l m n o p q r s t u v w x y z; do
29f08c3bdfSopenharmony_ci		ROD echo "Test" > "dir/$i"
30f08c3bdfSopenharmony_ci	done
31f08c3bdfSopenharmony_ci
32f08c3bdfSopenharmony_ci	ROD find dir -type f > filelist
33f08c3bdfSopenharmony_ci	EXPECT_PASS cpio -o $ARCHIVE_FORMAT \> cpio.out \< filelist
34f08c3bdfSopenharmony_ci	ROD mv "dir" "dir_orig"
35f08c3bdfSopenharmony_ci	ROD mkdir "dir"
36f08c3bdfSopenharmony_ci	EXPECT_PASS cpio -i \< cpio.out
37f08c3bdfSopenharmony_ci
38f08c3bdfSopenharmony_ci	if diff -r "dir" "dir_orig"; then
39f08c3bdfSopenharmony_ci		tst_res TPASS "Directories dir and dir_orig are equal"
40f08c3bdfSopenharmony_ci	else
41f08c3bdfSopenharmony_ci		tst_res TFAIL "Directories dir and dir_orig differ"
42f08c3bdfSopenharmony_ci		ls -R dir_orig
43f08c3bdfSopenharmony_ci		echo
44f08c3bdfSopenharmony_ci		ls -R dir
45f08c3bdfSopenharmony_ci	fi
46f08c3bdfSopenharmony_ci}
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_ci. tst_test.sh
49f08c3bdfSopenharmony_citst_run
50