blob: 650b41536ba7941cd8e3ef9671cef2d170739d5c [file] [log] [blame]
phajdan.jr@chromium.orgefd74402010-09-03 23:54:36 +00001// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <stdio.h>
6
7#include "base/at_exit.h"
8#include "base/command_line.h"
akalin@chromium.org3dfcd452010-11-18 22:29:38 +00009#include "base/file_path.h"
phajdan.jr@chromium.orgefd74402010-09-03 23:54:36 +000010#include "base/logging.h"
11#include "base/message_loop.h"
12#include "net/test/test_server.h"
13
14static void PrintUsage() {
akalin@chromium.org154bb132010-11-12 02:20:27 +000015 printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n");
phajdan.jr@chromium.orgefd74402010-09-03 23:54:36 +000016 printf("(NOTE: relpath should be relative to the 'src' directory)\n");
17}
18
19int main(int argc, const char* argv[]) {
20 base::AtExitManager at_exit_manager;
21 MessageLoopForIO message_loop;
22
23 // Process command line
24 CommandLine::Init(argc, argv);
25 CommandLine* command_line = CommandLine::ForCurrentProcess();
26
akalin@chromium.org3dfcd452010-11-18 22:29:38 +000027 if (!logging::InitLogging(FILE_PATH_LITERAL("testserver.log"),
28 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
29 logging::LOCK_LOG_FILE,
30 logging::APPEND_TO_OLD_LOG_FILE)) {
31 printf("Error: could not initialize logging. Exiting.\n");
32 return -1;
33 }
34
phajdan.jr@chromium.orgefd74402010-09-03 23:54:36 +000035 if (command_line->GetSwitchCount() == 0 ||
36 command_line->HasSwitch("help")) {
37 PrintUsage();
38 return -1;
39 }
40
phajdan.jr@chromium.orgefd74402010-09-03 23:54:36 +000041 net::TestServer::Type server_type(net::TestServer::TYPE_HTTP);
42 if (command_line->HasSwitch("https")) {
43 server_type = net::TestServer::TYPE_HTTPS;
44 } else if (command_line->HasSwitch("ftp")) {
45 server_type = net::TestServer::TYPE_FTP;
akalin@chromium.org154bb132010-11-12 02:20:27 +000046 } else if (command_line->HasSwitch("sync")) {
47 server_type = net::TestServer::TYPE_SYNC;
48 }
49
50 FilePath doc_root = command_line->GetSwitchValuePath("doc-root");
51 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) {
52 printf("Error: --doc-root must be specified\n");
53 PrintUsage();
54 return -1;
phajdan.jr@chromium.orgefd74402010-09-03 23:54:36 +000055 }
56
57 net::TestServer test_server(server_type, doc_root);
58 if (!test_server.Start()) {
59 printf("Error: failed to start test server. Exiting.\n");
60 return -1;
61 }
62
63 printf("testserver running at %s (type ctrl+c to exit)\n",
64 test_server.host_port_pair().ToString().c_str());
65
66 message_loop.Run();
67 return 0;
68}