File: mock-sysfs.h

package info (click to toggle)
bolt 0.7-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,396 kB
  • sloc: ansic: 21,784; python: 1,574; xml: 426; sh: 25; makefile: 13
file content (127 lines) | stat: -rw-r--r-- 5,301 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright © 2018 Red Hat, Inc
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *       Christian J. Kellner <christian@kellner.me>
 */


#pragma once

#include <gio/gio.h>

#include "bolt-enums.h"


G_BEGIN_DECLS

typedef struct MockDevId
{

  gint        vendor_id;
  const char *vendor_name;

  gint        device_id;
  const char *device_name;

  const char *unique_id;

} MockDevId;

#define MOCK_TYPE_SYSFS mock_sysfs_get_type ()
G_DECLARE_FINAL_TYPE (MockSysfs, mock_sysfs, MOCK, SYSFS, GObject);

MockSysfs *      mock_sysfs_new (void);

const char *     mock_sysfs_force_power_add (MockSysfs *ms);

gboolean         mock_sysfs_force_power_remove (MockSysfs *ms);

void             mock_sysfs_force_power_load (MockSysfs *ms);

void             mock_sysfs_force_power_unload (MockSysfs *ms);

char *           mock_sysfs_force_power_read (MockSysfs *ms);

gboolean         mock_sysfs_force_power_enabled (MockSysfs *ms);

const char *     mock_sysfs_domain_add (MockSysfs   *ms,
                                        BoltSecurity security,
                                        GStrv        bootacl);

const char *     mock_sysfs_domain_get_syspath (MockSysfs  *ms,
                                                const char *id);

gboolean         mock_sysfs_domain_remove (MockSysfs  *ms,
                                           const char *id);

GStrv            mock_sysfs_domain_bootacl_get (MockSysfs  *ms,
                                                const char *id,
                                                GError    **error);

gboolean         mock_sysfs_domain_bootacl_set (MockSysfs  *ms,
                                                const char *id,
                                                GStrv       acl,
                                                GError    **error);

const char *     mock_sysfs_host_add (MockSysfs  *ms,
                                      const char *domain,
                                      MockDevId  *id);

const char *     mock_sysfs_device_add (MockSysfs  *ms,
                                        const char *parent,
                                        MockDevId  *id,
                                        guint       authorized,
                                        const char *key,
                                        gint        boot);

const char *     mock_sysfs_device_get_syspath (MockSysfs  *ms,
                                                const char *id);

const char *     mock_sysfs_device_get_parent (MockSysfs  *ms,
                                               const char *id);

gboolean         mock_sysfs_device_remove (MockSysfs  *ms,
                                           const char *id);

/* helper macro */

/* *INDENT-OFF* */
#define bolt_assert_strv_equal(a, b, n) G_STMT_START {                                \
    const GStrv sa__ = (a);                                                           \
    const GStrv sb__ = (b);                                                           \
    guint al__ = a != NULL ? g_strv_length (sa__) : 0;                                \
    guint bl__ = b != NULL ? g_strv_length (sb__) : 0;                                \
    if (n > 0) {                                                                      \
        al__ = MIN ((guint) n, al__);                                                 \
        bl__ = MIN ((guint) n, bl__);                                                 \
      }                                                                               \
    if (al__ != bl__)                                                                 \
      g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC,        \
                                  "len(" #a ") == len(" #b ")",                       \
                                  (long double) al__, "!=", (long double) bl__, 'i'); \
    else                                                                              \
      for (guint il__ = 0; il__ < al__; il__++)                                       \
        if (g_strcmp0 (sa__[il__], sb__[il__]) == 0) {; } else {                      \
          g_autofree char *va__ = NULL;                                               \
          va__ = g_strdup_printf (#a "[%u] != " #b "[%u]", il__, il__ );              \
          g_assertion_message_cmpstr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC,    \
                                      va__, sa__[il__], "!=", sb__[il__]);            \
        }                                                                             \
    } G_STMT_END
/* *INDENT-ON* */

G_END_DECLS