logger_lock_test.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <log/macros.h>
  15. #include <log/logger_support.h>
  16. #include <log/log_messages.h>
  17. #include "util/interprocess_sync.h"
  18. #include "log_test_messages.h"
  19. #include <iostream>
  20. using namespace std;
  21. using namespace isc::log;
  22. class MockLoggingSync : public isc::util::InterprocessSync {
  23. public:
  24. /// \brief Constructor
  25. MockLoggingSync(const std::string& component_name) :
  26. InterprocessSync(component_name)
  27. {}
  28. protected:
  29. virtual bool lock() {
  30. cout << "FIELD1 FIELD2 LOGGER_LOCK_TEST: LOCK\n";
  31. return (true);
  32. }
  33. virtual bool tryLock() {
  34. cout << "FIELD1 FIELD2 LOGGER_LOCK_TEST: TRYLOCK\n";
  35. return (true);
  36. }
  37. virtual bool unlock() {
  38. cout << "FIELD1 FIELD2 LOGGER_LOCK_TEST: UNLOCK\n";
  39. return (true);
  40. }
  41. };
  42. /// \brief Test logger lock sequence
  43. ///
  44. /// A program used in testing the logger. It verifies that (1) an
  45. /// interprocess sync lock is first acquired by the logger, (2) the
  46. /// message is logged by the logger, and (3) the lock is released in
  47. /// that sequence.
  48. int
  49. main(int, char**) {
  50. initLogger();
  51. Logger logger("log");
  52. logger.setInterprocessSync(new MockLoggingSync("log"));
  53. LOG_INFO(logger, LOG_LOCK_TEST_MESSAGE);
  54. return (0);
  55. }