]>
Commit | Line | Data |
---|---|---|
c886eb9d AM |
1 | From e76ec6107f63fbf17cc6daf00a9cdb21994e54c1 Mon Sep 17 00:00:00 2001 |
2 | From: Wang Dong <dongdwdw@linux.vnet.ibm.com> | |
3 | Date: Thu, 20 Apr 2017 10:20:07 +0200 | |
4 | Subject: [PATCH 75/75] libparted/dasd: add test cases for the new fdasd | |
5 | functions | |
6 | ||
7 | The test case uses a temporary file in libparted/tests under | |
8 | Check framwork.It can be issued by "make check" in the test dir. | |
9 | ||
10 | Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com> | |
11 | Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com> | |
12 | --- | |
13 | libparted/tests/t4000-volser.sh | 20 +++++ | |
14 | libparted/tests/volser.c | 188 ++++++++++++++++++++++++++++++++++++++++ | |
15 | 2 files changed, 208 insertions(+) | |
16 | create mode 100755 libparted/tests/t4000-volser.sh | |
17 | create mode 100644 libparted/tests/volser.c | |
18 | ||
19 | diff --git a/libparted/tests/t4000-volser.sh b/libparted/tests/t4000-volser.sh | |
20 | new file mode 100755 | |
21 | index 0000000..89688ba | |
22 | --- /dev/null | |
23 | +++ b/libparted/tests/t4000-volser.sh | |
24 | @@ -0,0 +1,20 @@ | |
25 | +#!/bin/sh | |
26 | + | |
27 | +# This program is free software; you can redistribute it and/or modify | |
28 | +# it under the terms of the GNU General Public License as published by | |
29 | +# the Free Software Foundation; either version 3 of the License, or | |
30 | +# (at your option) any later version. | |
31 | + | |
32 | +# This program is distributed in the hope that it will be useful, | |
33 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
34 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
35 | +# GNU General Public License for more details. | |
36 | + | |
37 | +# You should have received a copy of the GNU General Public License | |
38 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
39 | + | |
40 | +. "${top_srcdir=../..}/tests/init.sh"; path_prepend_ . | |
41 | + | |
42 | +volser || fail=1 | |
43 | + | |
44 | +Exit $fail | |
45 | diff --git a/libparted/tests/volser.c b/libparted/tests/volser.c | |
46 | new file mode 100644 | |
47 | index 0000000..9063821 | |
48 | --- /dev/null | |
49 | +++ b/libparted/tests/volser.c | |
50 | @@ -0,0 +1,188 @@ | |
51 | +/* | |
52 | + * Author: Wang Dong <dongdwdw@cn.ibm.com> | |
53 | + */ | |
54 | + | |
55 | +#include <config.h> | |
56 | +#include <unistd.h> | |
57 | +#include <check.h> | |
58 | + | |
59 | +#include <parted/vtoc.h> | |
60 | +#include <parted/device.h> | |
61 | +#include <parted/fdasd.h> | |
62 | +#include <parted/vtoc.h> | |
63 | +#include "../arch/linux.h" | |
64 | +#include "common.h" | |
65 | +#include "progname.h" | |
66 | + | |
67 | +/* set dasd first */ | |
68 | +static char vol_devno[7] = {0}; | |
69 | +static char *tmp_disk; | |
70 | +static int fd; | |
71 | + | |
72 | +static PedDisk *disk; | |
73 | +static struct fdasd_anchor anc; | |
74 | +static fdasd_anchor_t *anchor = &anc; | |
75 | +static LinuxSpecific *arch_specific; | |
76 | + | |
77 | +/* set the enviroment */ | |
78 | +static void set_test (void) | |
79 | +{ | |
80 | + PedDevice *dev; | |
81 | + PedDiskType *type; | |
82 | + type = ped_disk_type_get ("dasd"); | |
83 | + | |
84 | + tmp_disk = _create_disk (20*1024*1024); | |
85 | + fail_if (tmp_disk == NULL, "Failed to create temporary disk"); | |
86 | + dev = ped_device_get (tmp_disk); | |
87 | + if (dev == NULL) | |
88 | + return; | |
89 | + | |
90 | + disk = _create_disk_label (dev, type); | |
91 | + if (!ped_device_open (disk->dev)) | |
92 | + return; | |
93 | + | |
94 | + fdasd_initialize_anchor (anchor); | |
95 | + arch_specific = LINUX_SPECIFIC (disk->dev); | |
96 | + fd = arch_specific->fd; | |
97 | + if (!fdasd_get_geometry (dev, anchor, fd)) | |
98 | + return; | |
99 | + | |
100 | + fdasd_check_volume (anchor, fd); | |
101 | + sprintf (vol_devno, "0X%04x", anchor->devno); | |
102 | + ck_assert (strlen (vol_devno) == VOLSER_LENGTH); | |
103 | +} | |
104 | + | |
105 | +static void free_test (void) | |
106 | +{ | |
107 | + ped_device_close (disk->dev); | |
108 | + ped_device_destroy (disk->dev); | |
109 | + unlink (tmp_disk); | |
110 | + free (tmp_disk); | |
111 | + fdasd_cleanup (anchor); | |
112 | +} | |
113 | + | |
114 | +/* Test with default volser */ | |
115 | +START_TEST (test_get_volser) | |
116 | +{ | |
117 | + char volser[7] = {0}; | |
118 | + fdasd_change_volser (anchor, vol_devno); | |
119 | + fdasd_write_labels (anchor, fd); | |
120 | + | |
121 | + fdasd_get_volser (anchor, volser, fd); | |
122 | + ck_assert (!strcmp (volser, vol_devno)); | |
123 | +} | |
124 | +END_TEST | |
125 | + | |
126 | +START_TEST (test_check_volser) | |
127 | +{ | |
128 | + char vol[7] = {0}; | |
129 | + char vol_long[] = "abcdefg"; | |
130 | + char vol_short[] = "ab_c "; | |
131 | + char vol_null[] = " "; | |
132 | + char *vol_input = NULL; | |
133 | + | |
134 | + vol_input = vol_long; | |
135 | + fdasd_check_volser (vol_input, anchor->devno); | |
136 | + ck_assert(!strcmp (vol_input, "ABCDEF")); | |
137 | + | |
138 | + vol_input = vol_short; | |
139 | + fdasd_check_volser (vol_input, anchor->devno); | |
140 | + ck_assert (!strcmp (vol_input, "ABC")); | |
141 | + | |
142 | + vol_input = vol_null; | |
143 | + fdasd_check_volser (vol_input, anchor->devno); | |
144 | + ck_assert (!strcmp (vol_input, vol_devno)); | |
145 | +} | |
146 | +END_TEST | |
147 | + | |
148 | +START_TEST (test_change_volser) | |
149 | +{ | |
150 | + | |
151 | + char vol[] = "000000"; | |
152 | + char volser[7] = {0}; | |
153 | + | |
154 | + fdasd_change_volser (anchor, vol); | |
155 | + fdasd_write_labels (anchor, fd); | |
156 | + | |
157 | + fdasd_get_volser (anchor, volser, fd); | |
158 | + ck_assert (!strcmp (volser, vol)); | |
159 | +} | |
160 | +END_TEST | |
161 | + | |
162 | +/* | |
163 | + * fdsad_recreate_vtoc recreate the VTOC with existing one. | |
164 | + * So the partition information should be not changed after recreating | |
165 | + * VTOC. | |
166 | +*/ | |
167 | +START_TEST (test_reuse_vtoc) | |
168 | +{ | |
169 | + ds5ext_t before; | |
170 | + ds5ext_t after; | |
171 | + | |
172 | + memcpy (&before, &anchor->f5->DS5AVEXT, sizeof(ds5ext_t)); | |
173 | + | |
174 | + if (anchor->fspace_trk) { | |
175 | + fdasd_reuse_vtoc (anchor); | |
176 | + memcpy (&after, &anchor->f5->DS5AVEXT, sizeof(ds5ext_t)); | |
177 | + if ((before.t != after.t) && (before.fc != after.fc) && (before.ft != after.ft)) | |
178 | + ck_abort (); | |
179 | + } else { | |
180 | + fdasd_reuse_vtoc (anchor); | |
181 | + memcpy (&after, &anchor->f5->DS5AVEXT, sizeof(ds5ext_t)); | |
182 | + if ((before.t != after.t) && (before.fc != after.fc) && (before.ft != after.ft)) | |
183 | + ck_abort (); | |
184 | + } | |
185 | +} | |
186 | +END_TEST | |
187 | + | |
188 | +int main (int argc, char **argv) | |
189 | +{ | |
190 | + | |
191 | + set_program_name (argv[0]); | |
192 | + | |
193 | +#if defined __s390__ || defined __s390x__ | |
194 | + | |
195 | + int number_failed = 0; | |
196 | + | |
197 | + Suite *suite = suite_create ("Volser"); | |
198 | + | |
199 | + TCase *tcase_get = tcase_create ("Get"); | |
200 | + TCase *tcase_check = tcase_create ("Check"); | |
201 | + TCase *tcase_change = tcase_create ("Change"); | |
202 | + TCase *tcase_vtoc = tcase_create ("Vtoc"); | |
203 | + | |
204 | + ped_exception_set_handler (_test_exception_handler); | |
205 | + | |
206 | + tcase_add_checked_fixture (tcase_check, set_test, free_test); | |
207 | + tcase_add_test (tcase_check, test_check_volser); | |
208 | + tcase_set_timeout (tcase_check, 0); | |
209 | + suite_add_tcase (suite, tcase_check); | |
210 | + | |
211 | + tcase_add_checked_fixture (tcase_change, set_test, free_test); | |
212 | + tcase_add_test (tcase_change, test_change_volser); | |
213 | + tcase_set_timeout (tcase_change, 0); | |
214 | + suite_add_tcase (suite, tcase_change); | |
215 | + | |
216 | + tcase_add_checked_fixture (tcase_get, set_test, free_test); | |
217 | + tcase_add_test (tcase_get, test_get_volser); | |
218 | + tcase_set_timeout (tcase_get, 0); | |
219 | + suite_add_tcase (suite, tcase_get); | |
220 | + | |
221 | + tcase_add_checked_fixture (tcase_vtoc, set_test, free_test); | |
222 | + tcase_add_test (tcase_vtoc, test_reuse_vtoc); | |
223 | + tcase_set_timeout (tcase_vtoc, 0); | |
224 | + suite_add_tcase (suite, tcase_vtoc); | |
225 | + | |
226 | + SRunner *srunner = srunner_create (suite); | |
227 | + /* When to debug, uncomment this line */ | |
228 | + /* srunner_set_fork_status (srunner, CK_NOFORK); */ | |
229 | + | |
230 | + srunner_run_all (srunner, CK_VERBOSE); | |
231 | + | |
232 | + number_failed = srunner_ntests_failed (srunner); | |
233 | + srunner_free (srunner); | |
234 | + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; | |
235 | + | |
236 | +#endif | |
237 | + return 0; | |
238 | +} | |
239 | -- | |
240 | 2.9.3 | |
241 |