~ubuntu-branches/ubuntu/utopic/mir/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/mir_test_framework/udev_environment.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-03-10 19:28:46 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: package-import@ubuntu.com-20140310192846-rq9qm3ec26yrelo2
Tags: upstream-0.1.6+14.04.20140310
ImportĀ upstreamĀ versionĀ 0.1.6+14.04.20140310

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include <umockdev.h>
23
23
 
 
24
#include <sys/types.h>
 
25
#include <sys/stat.h>
 
26
#include <unistd.h>
24
27
#include <fstream>
25
28
#include <sstream>
26
29
#include <string>
41
44
    g_object_unref(testbed);
42
45
}
43
46
 
44
 
void mtf::UdevEnvironment::add_standard_drm_devices()
45
 
{
46
 
    // Temporary, until umockdev grows add_from_file
47
 
    std::ifstream udev_dump(UDEVMOCK_DIR"/standard-drm-devices.umockdev");
48
 
    std::stringstream buffer;
49
 
    buffer<<udev_dump.rdbuf();
50
 
 
51
 
    umockdev_testbed_add_from_string(testbed,
52
 
                                     buffer.str().c_str(),
53
 
                                     NULL);
54
 
}
55
 
 
56
47
std::string mtf::UdevEnvironment::add_device(char const* subsystem,
57
48
                                             char const* name,
58
49
                                             char const* parent,
75
66
    if (syspath == nullptr)
76
67
        BOOST_THROW_EXCEPTION(std::runtime_error("Failed to create mock udev device"));
77
68
 
78
 
    umockdev_testbed_uevent(testbed, syspath, "add");
79
 
 
80
69
    std::string retval(syspath);
81
70
    g_free(syspath);
82
71
    return retval;
92
81
{
93
82
    umockdev_testbed_uevent(testbed, device_path.c_str(), "change");
94
83
}
 
84
 
 
85
void mtf::UdevEnvironment::add_standard_device(std::string const& name)
 
86
{
 
87
    auto descriptor_filename = std::string(UDEVMOCK_DIR) + "/" + name + ".umockdev";
 
88
    GError* err = nullptr;
 
89
    if (!umockdev_testbed_add_from_file(testbed, descriptor_filename.c_str(), &err))
 
90
    {
 
91
        BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Failed to create mock udev device: ") +
 
92
                                                 err->message));
 
93
    }
 
94
    
 
95
    auto ioctls_filename = std::string(UDEVMOCK_DIR) + "/" + name + ".ioctl";
 
96
    struct stat sb;
 
97
    if (stat(ioctls_filename.c_str(), &sb) == 0)
 
98
    {
 
99
        if (S_ISREG(sb.st_mode) || S_ISLNK(sb.st_mode))
 
100
        {
 
101
            if (!umockdev_testbed_load_ioctl(testbed, NULL, ioctls_filename.c_str(), &err))
 
102
            {
 
103
                BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Failed to load ioctl recording: ") +
 
104
                                                         err->message));
 
105
            }
 
106
        }
 
107
    }
 
108
}