• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) International Business Machines Corp., 2001
4# Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
5# Author: Manoj Iyer <manjo@mail.utexas.edu>
6#
7# Basic test for ln
8
9TST_CNT=6
10TST_TESTFUNC=do_test
11TST_SETUP=setup
12TST_NEEDS_TMPDIR=1
13. tst_test.sh
14
15setup()
16{
17	ROD mkdir -p dir/subdir
18	ROD echo "LTP" > file
19	ROD touch dir/file
20}
21
22check_dir_link()
23{
24	local dname="$1"
25	local lname="$2"
26
27	ROD ls "$lname" > lname.out
28	ROD ls "$dname" > dname.out
29
30	if diff lname.out dname.out; then
31		tst_res TPASS "Directory and link content is equal"
32	else
33		tst_res TFAIL "Directory and link content differs"
34		cat lname.out
35		echo
36		cat dname.out
37	fi
38}
39
40check_file_link()
41{
42	local fname="$1"
43	local lname="$2"
44
45	if diff $fname $lname; then
46		tst_res TPASS "File and link content is equal"
47	else
48		tst_res TFAIL "File and link content differs"
49	fi
50}
51
52ln_test()
53{
54	local args="$1"
55	local src="$2"
56	local link="$3"
57
58	EXPECT_PASS ln $args $src $link
59
60	if [ -f $src ]; then
61		check_file_link $src $link
62	else
63		check_dir_link $src $link
64	fi
65
66	ROD rm $link
67}
68
69do_test()
70{
71	case $1 in
72	1) ln_test ""   "file"      "file_link";;
73	2) ln_test "-s" "file"      "file_link";;
74	3) ln_test "-s" "dir"       "dir_link";;
75	4) ln_test ""   "$PWD/file" "file_link";;
76	5) ln_test "-s" "$PWD/file" "file_link";;
77	6) ln_test "-s" "$PWD/dir"  "dir_link";;
78	esac
79}
80
81tst_run
82