1 /*
2  * Copyright (C) 2016, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <gtest/gtest.h>
18 #include <utils/StrongPointer.h>
19 
20 #include "android/net/wifi/IClientInterface.h"
21 #include "android/net/wifi/IWificond.h"
22 #include "wificond/tests/integration/process_utils.h"
23 #include "wificond/tests/shell_utils.h"
24 
25 using android::net::wifi::IClientInterface;
26 using android::net::wifi::IWificond;
27 using android::sp;
28 using android::wificond::tests::integration::RunShellCommand;
29 using android::wificond::tests::integration::ScopedDevModeWificond;
30 using android::wificond::tests::integration::SupplicantIsDead;
31 using android::wificond::tests::integration::SupplicantIsRunning;
32 using android::wificond::tests::integration::WaitForTrue;
33 using android::wificond::tests::integration::WificondIsDead;
34 
35 namespace android {
36 namespace wificond {
37 namespace {
38 
39 constexpr int kTimeoutSeconds = 3;
40 
41 }  // namespace
42 
TEST(ServiceTest,ShouldTearDownSystemOnStartup)43 TEST(ServiceTest, ShouldTearDownSystemOnStartup) {
44   // Simulate doing normal connectivity things by startup supplicant.
45   ScopedDevModeWificond dev_mode;
46   sp<IWificond> service = dev_mode.EnterDevModeOrDie();
47 
48   sp<IClientInterface> client_interface;
49   EXPECT_TRUE(service->createClientInterface(&client_interface).isOk());
50 
51   bool supplicant_started = false;
52   EXPECT_TRUE(client_interface->enableSupplicant(&supplicant_started).isOk());
53   EXPECT_TRUE(supplicant_started);
54 
55   EXPECT_TRUE(WaitForTrue(SupplicantIsRunning, kTimeoutSeconds));
56 
57   // Kill wificond abruptly.  It should not clean up on the way out.
58   RunShellCommand("stop wificond");
59   EXPECT_TRUE(WaitForTrue(WificondIsDead, kTimeoutSeconds));
60 
61   // Supplicant should still be up.
62   EXPECT_TRUE(SupplicantIsRunning());
63 
64   // Restart wificond, which should kill supplicant on startup.
65   service = dev_mode.EnterDevModeOrDie();
66   EXPECT_TRUE(WaitForTrue(SupplicantIsDead, kTimeoutSeconds));
67 }
68 
69 }  // namespace wificond
70 }  // namespace android
71