Mir

Merge lp:~cemil-azizoglu/mir/MesaBufferAllocatorTest-failure-under-sbuild into lp:mir

Proposed by Cemil Azizoglu
Status: Merged
Approved by: Cemil Azizoglu
Approved revision: no longer in the source branch.
Merged at revision: 1981
Proposed branch: lp:~cemil-azizoglu/mir/MesaBufferAllocatorTest-failure-under-sbuild
Merge into: lp:mir
Diff against target: 89 lines (+32/-5)
2 files modified
src/platform/graphics/mesa/anonymous_shm_file.cpp (+11/-1)
tests/unit-tests/graphics/mesa/test_anonymous_shm_file.cpp (+21/-4)
To merge this branch: bzr merge lp:~cemil-azizoglu/mir/MesaBufferAllocatorTest-failure-under-sbuild
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Robert Carr (community) Approve
Daniel van Vugt Approve
Alan Griffiths Abstain
Alexandros Frantzis (community) Needs Fixing
Chris Halse Rogers Pending
Review via email: mp+237495@code.launchpad.net

Commit message

When XDG_RUNTIME_DIR is defined but pointing to a non-existing-directory, use "/tmp" (LP: #1304873).

Description of the change

mir_unit_tests.MesaBufferAllocatorTest.* test fails under sbuild chroot env. (LP: #1304873)

This is due to the fact that $XDG_RUNTIME_DIR exported in the sbuild chroot env corresponding to a non-existent directory. A better solution would be to use shm with a O_TMPFILE, but due to build machines using older kernels this isn't feasible at the moment.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

We could avoid the try/catch clause by using the boost::system::error_code overload instead:

if (runtime_dir)
{
    boost::system::error_code ec;
    boost::filesystem::path p(runtime_dir);
    runtime_dir_valid = boost::filesystem::is_directory(p, ec);
}

or even just stat():

struct stat sb;
bool const runtime_dir_valid = runtime_dir && !stat(runtime_dir, sb) && S_ISDIR(sb.st_mode);

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

@"A better solution would be to use shm with a O_TMPFILE which is what this proposal is doing." - if only that were true. ;)

I don't like fallbacks in production code to cover situations that should only occur in tests. They tend to obscure problems in live running. (We don't want to use /tmp in a real system.)

An alternative solution be to set $XDG_RUNTIME_DIR to "/tmp" in MesaBufferAllocatorTest?

However, we already use "/tmp" if $XDG_RUNTIME_DIR isn't set, so it isn't introducing any new issue.

review: Abstain
Revision history for this message
Chris Halse Rogers (raof) wrote :

Can we just go back to O_TMPFILE and not fail the test when O_TMPFILE returns EISDIR (indicating that the kernel doesn't support O_TMPFILE)?

Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

> Can we just go back to O_TMPFILE and not fail the test when O_TMPFILE returns
> EISDIR (indicating that the kernel doesn't support O_TMPFILE)?

I socialized that idea but neither duflu, nor alan_g was thrilled.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Actually I like the idea of O_TMPFILE so long as it's not the only option and we have a fallback for systems that lack O_TMPFILE support, like this approach.

Minor nit: You're testing the value of runtime_dir_valid on all code paths including that for which it's guaranteed to be false. So this:
  target_dir = (runtime_dir_valid ? runtime_dir : "/tmp");
could move inside the previous if-statement with some rearrangement.

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

P.S. I did approve of the previous O_TMPFILE form, for the record. Only disapproved of unrelated build-dep changes being included (now fixed). Also, Cemil found there was a CI problem with it (like some CI machine didn't have a new enough kernel for O_TMPFILE?).

Revision history for this message
Robert Carr (robertcarr) wrote :

This should be able to land?

review: Approve
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

Let's get this out. We can add the O_TMPFILE code on top of it.

Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/platform/graphics/mesa/anonymous_shm_file.cpp'
2--- src/platform/graphics/mesa/anonymous_shm_file.cpp 2014-10-06 03:02:44 +0000
3+++ src/platform/graphics/mesa/anonymous_shm_file.cpp 2014-10-08 15:34:57 +0000
4@@ -20,6 +20,7 @@
5 #include "anonymous_shm_file.h"
6
7 #include <boost/throw_exception.hpp>
8+#include <boost/filesystem.hpp>
9 #include <stdexcept>
10
11 #include <vector>
12@@ -38,7 +39,16 @@
13 {
14 char const* const tmpl = "/mir-buffer-XXXXXX";
15 char const* const runtime_dir = getenv("XDG_RUNTIME_DIR");
16- char const* const target_dir = runtime_dir ? runtime_dir : "/tmp";
17+ bool runtime_dir_valid = false;
18+
19+ if (runtime_dir)
20+ {
21+ boost::system::error_code ec;
22+ boost::filesystem::path p(runtime_dir);
23+ runtime_dir_valid = boost::filesystem::is_directory(p, ec);
24+ }
25+
26+ char const* const target_dir = (runtime_dir_valid ? runtime_dir : "/tmp");
27
28 /* We need a mutable array for mkostemp */
29 std::vector<char> path(target_dir, target_dir + strlen(target_dir));
30
31=== modified file 'tests/unit-tests/graphics/mesa/test_anonymous_shm_file.cpp'
32--- tests/unit-tests/graphics/mesa/test_anonymous_shm_file.cpp 2014-10-01 03:41:21 +0000
33+++ tests/unit-tests/graphics/mesa/test_anonymous_shm_file.cpp 2014-10-08 15:34:57 +0000
34@@ -183,7 +183,7 @@
35 TEST(AnonymousShmFile, is_created_and_deleted_in_xdg_runtime_dir)
36 {
37 using namespace testing;
38-
39+
40 TemporaryDirectory const temp_dir;
41 TemporaryEnvironmentValue const env{"XDG_RUNTIME_DIR", temp_dir.path()};
42 PathWatcher const path_watcher{temp_dir.path()};
43@@ -201,7 +201,7 @@
44 TEST(AnonymousShmFile, is_created_and_deleted_in_tmp_dir)
45 {
46 using namespace testing;
47-
48+
49 TemporaryEnvironmentValue const env{"XDG_RUNTIME_DIR", nullptr};
50 PathWatcher const path_watcher{"/tmp"};
51 size_t const file_size{100};
52@@ -215,10 +215,27 @@
53 path_watcher.process_events();
54 }
55
56+TEST(AnonymousShmFile, is_created_and_deleted_in_tmp_dir_with_nonexistent_xdg_runtime_dir)
57+{
58+ using namespace testing;
59+
60+ TemporaryEnvironmentValue const env{"XDG_RUNTIME_DIR", "/non-existent-dir"};
61+ PathWatcher const path_watcher{"/tmp"};
62+ size_t const file_size{100};
63+
64+ InSequence s;
65+ EXPECT_CALL(path_watcher, file_created(StartsWith("mir-buffer-")));
66+ EXPECT_CALL(path_watcher, file_deleted(StartsWith("mir-buffer-")));
67+
68+ mgm::AnonymousShmFile shm_file{file_size};
69+
70+ path_watcher.process_events();
71+}
72+
73 TEST(AnonymousShmFile, has_correct_size)
74 {
75 using namespace testing;
76-
77+
78 TemporaryDirectory const temp_dir;
79 TemporaryEnvironmentValue const env{"XDG_RUNTIME_DIR", temp_dir.path()};
80 size_t const file_size{100};
81@@ -234,7 +251,7 @@
82 TEST(AnonymousShmFile, writing_to_base_ptr_writes_to_file)
83 {
84 using namespace testing;
85-
86+
87 TemporaryDirectory const temp_dir;
88 TemporaryEnvironmentValue const env{"XDG_RUNTIME_DIR", temp_dir.path()};
89 size_t const file_size{100};

Subscribers

People subscribed via source and target branches