source: mainline/uspace/srv/volsrv/test/volume.c@ 64ffd83

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 64ffd83 was 64ffd83, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Configuring mount point for (newly created) paritions.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2018 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <errno.h>
30#include <pcut/pcut.h>
31#include <str.h>
32
33#include "../volume.h"
34
35PCUT_INIT;
36
37PCUT_TEST_SUITE(volume);
38
39/** Volumes list creation and destruction. */
40PCUT_TEST(volumes_basic)
41{
42 vol_volumes_t *volumes;
43 errno_t rc;
44
45 rc = vol_volumes_create(&volumes);
46 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
47
48 vol_volumes_destroy(volumes);
49}
50
51/** Two references to the same volume, reference to a different volume. */
52PCUT_TEST(two_same_different)
53{
54 vol_volumes_t *volumes;
55 vol_volume_t *va, *vb, *va1;
56 errno_t rc;
57
58 rc = vol_volumes_create(&volumes);
59 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
60
61 rc = vol_volume_lookup_ref(volumes, "foo", &va);
62 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
63
64 rc = vol_volume_lookup_ref(volumes, "bar", &vb);
65 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
66
67 rc = vol_volume_lookup_ref(volumes, "foo", &va1);
68 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
69
70 PCUT_ASSERT_TRUE(va1 == va);
71
72 vol_volume_del_ref(va);
73 vol_volume_del_ref(vb);
74 vol_volume_del_ref(va1);
75
76 vol_volumes_destroy(volumes);
77}
78
79/** Reference the same volume twice, making sure it persists. */
80PCUT_TEST(same_twice)
81{
82 vol_volumes_t *volumes;
83 vol_volume_t *va;
84 errno_t rc;
85
86 rc = vol_volumes_create(&volumes);
87 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
88
89 /* Look up a volume */
90 rc = vol_volume_lookup_ref(volumes, "foo", &va);
91 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
92
93 /* Setting mount point forces it to persist after dropping the ref. */
94 rc = vol_volume_set_mountp(va, "/xyz");
95
96 /* Drop the reference */
97 vol_volume_del_ref(va);
98
99 /* Look up volume again */
100 rc = vol_volume_lookup_ref(volumes, "foo", &va);
101 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
102
103 /* The mount point should still be set */
104 PCUT_ASSERT_NOT_NULL(va->mountp);
105 PCUT_ASSERT_TRUE(str_cmp(va->mountp, "/xyz") == 0);
106
107 vol_volume_del_ref(va);
108
109 vol_volumes_destroy(volumes);
110}
111
112PCUT_EXPORT(volume);
Note: See TracBrowser for help on using the repository browser.