security/sandbox/linux/gtest/TestSandboxUtil.cpp
author Patrick Brosset <pbrosset@mozilla.com>
Mon, 22 Feb 2016 10:33:04 +0100
changeset 334119 bab3de413d374fbaf58f53117709ef34a3922c7b
parent 315799 c23905a01c29f257f64db3e627d07a1eb71eb0d0
child 489668 cbb8fdf1daf98a15f7d57f6b08d273bdf96aa1a0
child 648192 c236dfe7dc98c387219d7cb45d0693560db708fd
child 694109 98e2b4ee9775a2a2b5cc1bb8a390bfe901814f38
permissions -rw-r--r--
Bug 1246677 - 5 - Get rid of 'content' in ruleview test files; r=jdescottes MozReview-Commit-ID: Af07cexjJOv

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "gtest/gtest.h"

#include "SandboxUtil.h"
#include "SandboxInfo.h"

#include <pthread.h>

namespace mozilla {

// In order to test IsSingleThreaded when the test-running process is
// single-threaded, before assorted XPCOM components have created many
// additional threads, a static initializer is used.

namespace {

struct EarlyTest {
  bool mWasSingleThreaded;

  EarlyTest()
  : mWasSingleThreaded(IsSingleThreaded())
  { }
};

static const EarlyTest gEarlyTest;

} // namespace

TEST(SandboxUtil, IsSingleThreaded)
{
  // If the test system if affected by kUnexpectedThreads, (1) there's
  // no point in doing this test, and (2) if that happens on Mozilla
  // CI then burning the tree is an appropriate response.
  ASSERT_FALSE(SandboxInfo::Get().Test(SandboxInfo::kUnexpectedThreads));
  EXPECT_TRUE(gEarlyTest.mWasSingleThreaded);
  EXPECT_FALSE(IsSingleThreaded());
}

} // namespace mozilla