Skip to content

Commit

Permalink
Merge pull request #590 from Tarsnap/libcperciva-import
Browse files Browse the repository at this point in the history
Libcperciva import
  • Loading branch information
cperciva authored Oct 21, 2023
2 parents daec0b4 + c17190b commit 950c496
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 253 deletions.
10 changes: 5 additions & 5 deletions tests/01-trivial.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ no_args_stderr=${s_basename}-no-args.stderr

scenario_cmd() {
# Check --help.
setup_check_variables "check --help"
setup_check "check --help"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--help > "${help_stdout}"
echo $? > "${c_exitfile}"

# Check --version.
setup_check_variables "check --version"
setup_check "check --version"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--version > "${version_stdout}"
echo $? > "${c_exitfile}"

setup_check_variables "check --version output"
setup_check "check --version output"
grep -q "tarsnap" "${version_stdout}"
echo $? > "${c_exitfile}"

# Check no arguments (expect exit code 1, error message).
setup_check_variables "check no arguments"
setup_check "check no arguments"
${c_valgrind_cmd} ./tarsnap --no-default-config \
2> "${no_args_stderr}"
expected_exitcode 1 $? > "${c_exitfile}"

setup_check_variables "check no arguments output"
setup_check "check no arguments output"
grep -q "tarsnap: Must specify one of" "${no_args_stderr}"
echo $? > "${c_exitfile}"
}
6 changes: 3 additions & 3 deletions tests/02-c-dry-run-no-keyfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ out_stats_stderr=${s_basename}-output-stats.stderr
scenario_cmd() {
# Check -c --dry-run --print-stats. The precise stats
# will vary based on the system, so we can't check those.
setup_check_variables "check -c --dry-run"
setup_check "check -c --dry-run"
${c_valgrind_cmd} ./tarsnap --no-default-config \
-c --dry-run --print-stats \
"${samplefile}" \
2> "${out_stats_stderr}"
echo $? > "${c_exitfile}"

# Check expected warning message.
setup_check_variables "check -c --dry-run output"
setup_check "check -c --dry-run output"
grep -q "tarsnap: Removing leading" "${out_stats_stderr}"
echo $? > "${c_exitfile}"

# Check another expected warning message.
setup_check_variables "check -c --dry-run warning"
setup_check "check -c --dry-run warning"
grep -q "(sizes may be slightly inaccurate)" "${out_stats_stderr}"
echo $? > "${c_exitfile}"
}
8 changes: 4 additions & 4 deletions tests/03-c-dry-run-fake-keyfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ init_cache_stderr=${s_basename}-cachedir.stderr

scenario_cmd() {
# Create a cache directory.
setup_check_variables "check --initialize-cachedir"
setup_check "check --initialize-cachedir"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" --cachedir "${cachedir}" \
--initialize-cachedir \
2> "${init_cache_stderr}"
echo $? > "${c_exitfile}"

setup_check_variables "check --initialize-cachedir output"
setup_check "check --initialize-cachedir output"
grep -q "created for" "${init_cache_stderr}"
echo $? > "${c_exitfile}"

# Check -c --dry-run --print-stats. The precise stats
# will vary based on the system, so we can't check those.
# (This uses more code than a --dry-run without any keyfile.)
setup_check_variables "check -c --dry-run with fake key"
setup_check "check -c --dry-run with fake key"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" --cachedir "${cachedir}" \
-c --dry-run --print-stats \
"${samplefile}" \
2> "${out_stats_stderr}"
echo $? > "${c_exitfile}"

setup_check_variables "check -c --dry-run with fake key output"
setup_check "check -c --dry-run with fake key output"
grep -q "tarsnap: Removing leading" "${out_stats_stderr}"
echo $? > "${c_exitfile}"
}
32 changes: 16 additions & 16 deletions tests/04-c-d-real-keyfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ scenario_cmd() {
# Check for a keyfile.
if [ -z "${TARSNAP_TEST_KEYFILE-}" ]; then
# SKIP if we don't have a TARSNAP_TEST_KEYFILE.
setup_check_variables "real keyfile skip"
setup_check "real keyfile skip"
echo "-1" > "${c_exitfile}"
return
fi
keyfile=${TARSNAP_TEST_KEYFILE}

# Check that this key has no archives.
setup_check_variables "real keyfile --list-archives"
setup_check "real keyfile --list-archives"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" \
--list-archives \
Expand All @@ -38,7 +38,7 @@ scenario_cmd() {
fi

# Check that this key has no archives; error if it does.
setup_check_variables "real keyfile --list-archives output"
setup_check "real keyfile --list-archives output"
if [ -s "${list_archives_stdout}" ]; then
echo "Keyfile has archives! Bail."
echo "1" > "${c_exitfile}"
Expand All @@ -48,34 +48,34 @@ scenario_cmd() {
fi

# Create a cache directory.
setup_check_variables "real keyfile --initialize-cachedir"
setup_check "real keyfile --initialize-cachedir"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" --cachedir "${cachedir}" \
--initialize-cachedir \
2> "${init_cache_stderr}"
echo $? > "${c_exitfile}"

# Check --initialize-cachedir output.
setup_check_variables "real keyfile --initialize-cachedir output"
setup_check "real keyfile --initialize-cachedir output"
grep -q "created for" "${init_cache_stderr}"
echo $? > "${c_exitfile}"

# Fsck.
setup_check_variables "real key --fsck"
setup_check "real key --fsck"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" --cachedir "${cachedir}" \
--fsck \
> "${fsck_stdout}"
echo $? > "${c_exitfile}"

# Check fsck output.
setup_check_variables "real key --fsck output"
setup_check "real key --fsck output"
grep -q "Phase 5: Identifying unreferenced chunks" "${fsck_stdout}"
echo $? > "${c_exitfile}"

# Create an archive. The precise stats will vary based on
# the system, so we can't check those.
setup_check_variables "real key -c"
setup_check "real key -c"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" --cachedir "${cachedir}" \
-c --print-stats -f "${archivename}" \
Expand All @@ -84,17 +84,17 @@ scenario_cmd() {
echo $? > "${c_exitfile}"

# Check -c output.
setup_check_variables "real key -c output"
setup_check "real key -c output"
grep -q "tarsnap: Removing leading" "${create_stderr}"
echo $? > "${c_exitfile}"

setup_check_variables "real key -c output > 0"
setup_check "real key -c output > 0"
total=$( grep "All archives" "${create_stderr}" | awk '{ print $3 }' )
test "${total}" -gt 0
echo $? > "${c_exitfile}"

# Test the contents of the archive.
setup_check_variables "real key -t"
setup_check "real key -t"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" --cachedir "${cachedir}" \
-t -f "${archivename}" \
Expand All @@ -104,34 +104,34 @@ scenario_cmd() {
# Check -t output. The filename in the archive does not have a
# leading / (it was stripped by tarsnap), so we add it to the string
# we're checking so that it matches the ${samplefile}.
setup_check_variables "real key -t output"
setup_check "real key -t output"
list_contents="$(cat "${list_contents_stdout}")"
[ "/${list_contents}" = "${samplefile}" ]
echo $? > "${c_exitfile}"

# Extract the contents of the archive in the test output directory.
setup_check_variables "real key -x"
setup_check "real key -x"
mkdir "${extract_dir}"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" --cachedir "${cachedir}" \
-x -f "${archivename}" -C "${extract_dir}"
echo $? > "${c_exitfile}"

# Check -x output.
setup_check_variables "real key -x output"
setup_check "real key -x output"
cmp "${samplefile}" "${extract_dir}${samplefile}"
echo $? > "${c_exitfile}"

# Delete the archive.
setup_check_variables "real key -d"
setup_check "real key -d"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" --cachedir "${cachedir}" \
-d --print-stats -f "${archivename}" \
2> "${delete_stderr}"
echo $? > "${c_exitfile}"

# Check -d output; we should have no data left on the server.
setup_check_variables "real key -d output"
setup_check "real key -d output"
total=$( grep "All archives" "${delete_stderr}" | awk '{ print $3 }' )
test "${total}" -eq 0
echo $? > "${c_exitfile}"
Expand Down
8 changes: 4 additions & 4 deletions tests/05-passphrase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ passphrase="hunter2"

scenario_cmd() {
# Try to create a cache directory with a wrong passphrase.
setup_check_variables "check --initialize-cachedir, bad passphrase"
setup_check "check --initialize-cachedir, bad passphrase"
echo "wrong passphrase" | \
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" \
Expand All @@ -18,7 +18,7 @@ scenario_cmd() {
expected_exitcode 1 $? > "${c_exitfile}"

# Create a cache directory with the correct passphrase.
setup_check_variables "check --initialize-cachedir, passphrase stdin"
setup_check "check --initialize-cachedir, passphrase stdin"
echo "${passphrase}" | \
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" \
Expand All @@ -29,7 +29,7 @@ scenario_cmd() {
echo $? > "${c_exitfile}"

# Create a cache directory with the correct passphrase in env.
setup_check_variables "check --initialize-cachedir, passphrase env"
setup_check "check --initialize-cachedir, passphrase env"
PASSENV="hunter2" \
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" \
Expand All @@ -40,7 +40,7 @@ scenario_cmd() {
echo $? > "${c_exitfile}"

# Create a cache directory with the correct passphrase in a file.
setup_check_variables "check --initialize-cachedir, passphrase file"
setup_check "check --initialize-cachedir, passphrase file"
printf "hunter2\n" > "${s_basename}-passphrase.txt"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--keyfile "${keyfile}" \
Expand Down
16 changes: 8 additions & 8 deletions tests/06-progress-output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tmp="${s_basename}-tmp"

scenario_cmd() {
# Check tarsnap --dry-run -c -v
setup_check_variables "check -v"
setup_check "check -v"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--dry-run -c -C "${scriptdir}" \
-v \
Expand All @@ -20,12 +20,12 @@ scenario_cmd() {
echo $? > "${c_exitfile}"

# Check output of tarsnap --dry-run -c -v
setup_check_variables "check -v output"
setup_check "check -v output"
cmp "${out_v}" "${scriptdir}/06-progress-output-v.good"
echo $? > "${c_exitfile}"

# Check tarsnap --dry-run -c --progress-bytes 1k
setup_check_variables "check --progress-bytes 1k"
setup_check "check --progress-bytes 1k"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--dry-run -c -C "${scriptdir}" \
--progress-bytes 1k \
Expand All @@ -39,12 +39,12 @@ scenario_cmd() {
mv "${tmp}" "${out_pb}"

# Check output of tarsnap --dry-run -c --progress-bytes 1k
setup_check_variables "check --progress-bytes 1k output"
setup_check "check --progress-bytes 1k output"
cmp "${out_pb}" "${scriptdir}/06-progress-output-pb.good"
echo $? > "${c_exitfile}"

# Check tarsnap --dry-run -c -v --progress-bytes 1k
setup_check_variables "check -v --progress-bytes 1k"
setup_check "check -v --progress-bytes 1k"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--dry-run -c -C "${scriptdir}" \
-v --progress-bytes 1k \
Expand All @@ -58,12 +58,12 @@ scenario_cmd() {
mv "${tmp}" "${out_vpb_1k}"

# Check output of tarsnap --dry-run -c -v --progress-bytes 1k
setup_check_variables "check -v --progress-bytes 1k output"
setup_check "check -v --progress-bytes 1k output"
cmp "${out_vpb_1k}" "${scriptdir}/06-progress-output-vpb-1k.good"
echo $? > "${c_exitfile}"

# Check tarsnap --dry-run -c -v --progress-bytes 20k
setup_check_variables "check -v --progress-bytes 20k"
setup_check "check -v --progress-bytes 20k"
${c_valgrind_cmd} ./tarsnap --no-default-config \
--dry-run -c -C "${scriptdir}" \
-v --progress-bytes 20k \
Expand All @@ -77,7 +77,7 @@ scenario_cmd() {
mv "${tmp}" "${out_vpb_20k}"

# Check output of tarsnap --dry-run -c -v --progress-bytes 20k
setup_check_variables "check -v --progress-bytes 20k output"
setup_check "check -v --progress-bytes 20k output"
cmp "${out_vpb_20k}" "${scriptdir}/06-progress-output-vpb-20k.good"
echo $? > "${c_exitfile}"
}
Loading

0 comments on commit 950c496

Please sign in to comment.