Merge 9cb05f9446145b990f63eddabe959665783068b0 on remote branch

Change-Id: If3e74144590fdedc779eb0fd2d1a50f99f41745c
diff --git a/.appveyor.yml b/.appveyor.yml
deleted file mode 100644
index e75d59f..0000000
--- a/.appveyor.yml
+++ /dev/null
@@ -1,16 +0,0 @@
-environment:
-  matrix:
-  - TARGET: x86_64-pc-windows-msvc
-  - TARGET: i686-pc-windows-msvc
-  - TARGET: x86_64-pc-windows-gnu
-  - TARGET: i686-pc-windows-gnu
-install:
-  - curl -sSf -o rustup-init.exe https://win.rustup.rs/
-  - rustup-init.exe -y --default-host %TARGET%
-  - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
-  - rustc -vV
-  - cargo -vV
-build: false
-test_script:
-  - cargo build --verbose
-  - cargo test --verbose
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 6fcb99c..45e1a87 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,6 @@
 {
   "git": {
-    "sha1": "b347731fc0c008dbb88b406c595b1e644458fffe"
-  }
-}
+    "sha1": "5f1b03332000b4c4274b5bd35fac516049ff1c6b"
+  },
+  "path_in_vcs": ""
+}
\ No newline at end of file
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..f9adc30
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,166 @@
+name: CI
+on:
+  pull_request:
+  push:
+    branches:
+      - master
+
+env:
+  RUST_BACKTRACE: 1
+  CARGO_TERM_COLOR: always
+
+jobs:
+  ci-pass:
+    name: CI is green
+    runs-on: ubuntu-latest
+    needs:
+      - msrv
+      - test-linux
+      - test-macos
+      - test-windows
+      - build-cross
+      - test-cgroups
+    steps:
+      - run: exit 0
+
+  msrv:
+    runs-on: ubuntu-latest
+
+    strategy:
+      matrix:
+        rust:
+          - 1.13
+        target:
+          - x86_64-unknown-linux-gnu
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Run tests
+      run: |
+        rustup default ${{ matrix.rust }}
+        rustup target add ${{ matrix.target }}
+        cargo test --verbose --target ${{ matrix.target }}
+
+  test-linux:
+    runs-on: ubuntu-latest
+
+    strategy:
+      matrix:
+        rust:
+          - stable
+          - beta
+          - nightly
+        target:
+          - x86_64-unknown-linux-gnu
+          - x86_64-unknown-linux-musl
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Run tests
+      run: |
+        rustup default ${{ matrix.rust }}
+        rustup target add ${{ matrix.target }}
+        cargo test --verbose --target ${{ matrix.target }}
+
+  test-macos:
+    runs-on: macos-latest
+
+    strategy:
+      matrix:
+        rust:
+          - stable
+          - beta
+          - nightly
+        target:
+          - x86_64-apple-darwin
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Run tests
+      run: |
+        rustup default ${{ matrix.rust }}
+        rustup target add ${{ matrix.target }}
+        cargo test --verbose --target ${{ matrix.target }}
+
+  test-windows:
+    runs-on: windows-latest
+
+    strategy:
+      matrix:
+        rust:
+          - stable
+          - beta
+          - nightly
+        target:
+          - x86_64-pc-windows-gnu
+          - x86_64-pc-windows-msvc
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Run tests
+      run: |
+        rustup default ${{ matrix.rust }}
+        rustup target add ${{ matrix.target }}
+        cargo test --verbose --target ${{ matrix.target }}
+
+  build-cross:
+    runs-on: ubuntu-latest
+
+    strategy:
+      matrix:
+        rust:
+          - stable
+        target:
+          - aarch64-unknown-linux-gnu
+          - i686-pc-windows-gnu
+          - i686-pc-windows-msvc
+          - i686-unknown-linux-gnu
+          - aarch64-apple-darwin
+          - aarch64-pc-windows-msvc
+          - aarch64-unknown-linux-musl
+          - arm-unknown-linux-gnueabi
+          - arm-unknown-linux-gnueabihf
+          - armv7-unknown-linux-gnueabihf
+          - mips-unknown-linux-gnu
+          - mips64-unknown-linux-gnuabi64
+          - mips64el-unknown-linux-gnuabi64
+          - mipsel-unknown-linux-gnu
+          - powerpc-unknown-linux-gnu
+          - powerpc64-unknown-linux-gnu
+          - powerpc64le-unknown-linux-gnu
+          - riscv64gc-unknown-linux-gnu
+          - s390x-unknown-linux-gnu
+          - x86_64-unknown-freebsd
+          - x86_64-unknown-illumos
+          - x86_64-unknown-netbsd
+          - i686-linux-android
+          - x86_64-linux-android
+          - arm-linux-androideabi
+          - aarch64-linux-android
+          - x86_64-apple-ios
+          - asmjs-unknown-emscripten
+          - aarch64-apple-ios
+          - aarch64-apple-ios-sim
+          - aarch64-apple-darwin
+    steps:
+    - uses: actions/checkout@v2
+    - name: Run build
+      run: |
+        rustup default ${{ matrix.rust }}
+        rustup target add ${{ matrix.target }}
+        cargo build --verbose --target ${{ matrix.target }}
+
+  test-cgroups:
+    runs-on: ubuntu-latest
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Test Cgroup
+      run: |
+        docker build -f ci/cgroups/Dockerfile -t num-cpus-cgroups .
+        # Test without cgroups
+        docker run -e NUM_CPUS_TEST_GET=2 num-cpus-cgroups
+        # Only 1 CPU
+        docker run --cpus="1" -e NUM_CPUS_TEST_GET=1 num-cpus-cgroups
+        # 1.5 CPUs
+        docker run --cpus="1.5" -e NUM_CPUS_TEST_GET=2 num-cpus-cgroups
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index cec6ddb..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,81 +0,0 @@
-language: rust
-rust: stable
-dist: xenial
-sudo: false
-notifications:
-  email: disabled
-
-cache: cargo
-
-install:
-  - if [ -z "$NO_ADD" ]; then rustup target add "$TARGET"; fi
-
-script:
-  - cargo build --verbose --target "$TARGET"
-  # Only run the targets if we are on the same OS.
-  - if [ "$RUN" == "1" ]; then cargo test --verbose --target "$TARGET"; fi
-
-env:
-  global:
-    # Travis CI servers make 2 cores available to processes via virtualization.
-    # See https://docs.travis-ci.com/user/reference/overview/
-    - NUM_CPUS_TEST_GET=2
-
-matrix:
-  include:
-    # Linux
-    # Minimum Supported Rust Version
-    - name: Minimum Supported Rust Version
-      env: TARGET=x86_64-unknown-linux-gnu RUN=1 NO_ADD=1
-      rust: 1.13.0
-    # 32-bit requires multilib.
-    - env: TARGET=i686-unknown-linux-gnu RUN=1
-      addons:
-        apt:
-          packages:
-            - gcc-multilib
-    # 64-bit stable.
-    - env: TARGET=x86_64-unknown-linux-gnu RUN=1 NO_ADD=1
-      rust: stable
-    # 64-bit beta.
-    - env: TARGET=x86_64-unknown-linux-gnu RUN=1 NO_ADD=1
-      rust: beta
-    # 64-bit nightly.
-    - env: TARGET=x86_64-unknown-linux-gnu RUN=1 NO_ADD=1
-      rust: nightly
-
-    # Mac OS X
-    - os: osx
-      env: TARGET=x86_64-apple-darwin RUN=1 NO_ADD=1
-    # Android
-    # - for x86
-    - env: TARGET=i686-linux-android
-    - env: TARGET=x86_64-linux-android
-    # - for ARM
-    - env: TARGET=arm-linux-androideabi
-    - env: TARGET=aarch64-linux-android
-    # IOS
-    - os: osx
-      osx_image: xcode9
-      env: TARGET=x86_64-apple-ios
-    # FreeBSD
-    - env: TARGET=x86_64-unknown-freebsd
-    # Fuchsia
-    # FIXME: figure out why target is missing and re-enable
-    #- env: TARGET=x86_64-unknown-fuchsia
-    # NetBSD
-    - env: TARGET=x86_64-unknown-netbsd
-    # Emscripten
-    - env: TARGET=asmjs-unknown-emscripten
-
-    # CGroups in Docker
-    - name: Docker CGroups
-      install:
-      script:
-      - docker build -f ci/cgroups/Dockerfile -t num-cpus-cgroups .
-      # Test without cgroups
-      - docker run -it -e NUM_CPUS_TEST_GET=2 num-cpus-cgroups
-      # Only 1 CPU
-      - docker run -it --cpus="1" -e NUM_CPUS_TEST_GET=1 num-cpus-cgroups
-      # 1.5 CPUs
-      - docker run -it --cpus="1.5" -e NUM_CPUS_TEST_GET=2 num-cpus-cgroups
diff --git a/Android.bp b/Android.bp
index 82addfe..d737475 100644
--- a/Android.bp
+++ b/Android.bp
@@ -42,7 +42,7 @@
     host_supported: true,
     crate_name: "num_cpus",
     cargo_env_compat: true,
-    cargo_pkg_version: "1.13.0",
+    cargo_pkg_version: "1.13.1",
     srcs: ["src/lib.rs"],
     edition: "2015",
     rustlibs: [
@@ -64,7 +64,7 @@
     name: "num_cpus_test_src_lib",
     crate_name: "num_cpus",
     cargo_env_compat: true,
-    cargo_pkg_version: "1.13.0",
+    cargo_pkg_version: "1.13.1",
     srcs: ["src/lib.rs"],
     test_suites: ["general-tests"],
     auto_gen_config: true,
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0caafb2..5496ace 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## v1.13.1
+
+### Fixes
+
+- fix parsing zero or multiple optional fields in cgroup mountinfo.
+
 ## v1.13.0
 
 ### Features
diff --git a/Cargo.lock b/Cargo.lock
index 62c701c..93137c3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,26 +1,26 @@
 # This file is automatically @generated by Cargo.
 # It is not intended for manual editing.
+version = 3
+
 [[package]]
 name = "hermit-abi"
 version = "0.1.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120"
 dependencies = [
- "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc",
 ]
 
 [[package]]
 name = "libc"
 version = "0.2.65"
 source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8"
 
 [[package]]
 name = "num_cpus"
-version = "1.13.0"
+version = "1.13.1"
 dependencies = [
- "hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
+ "hermit-abi",
+ "libc",
 ]
-
-[metadata]
-"checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120"
-"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8"
diff --git a/Cargo.toml b/Cargo.toml
index 0bab66d..f708cc8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,25 +3,24 @@
 # When uploading crates to the registry Cargo will automatically
 # "normalize" Cargo.toml files for maximal compatibility
 # with all versions of Cargo and also rewrite `path` dependencies
-# to registry (e.g., crates.io) dependencies
+# to registry (e.g., crates.io) dependencies.
 #
-# If you believe there's an error in this file please file an
-# issue against the rust-lang/cargo repository. If you're
-# editing this file be aware that the upstream Cargo.toml
-# will likely look very different (and much more reasonable)
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
 
 [package]
 name = "num_cpus"
-version = "1.13.0"
+version = "1.13.1"
 authors = ["Sean McArthur <sean@seanmonstar.com>"]
 description = "Get the number of CPUs on a machine."
 documentation = "https://docs.rs/num_cpus"
 readme = "README.md"
 keywords = ["cpu", "cpus", "cores"]
 categories = ["hardware-support"]
-license = "MIT/Apache-2.0"
+license = "MIT OR Apache-2.0"
 repository = "https://github.com/seanmonstar/num_cpus"
-[dependencies.libc]
-version = "0.2.26"
 [target."cfg(all(any(target_arch = \"x86_64\", target_arch = \"aarch64\"), target_os = \"hermit\"))".dependencies.hermit-abi]
 version = "0.1.3"
+[target."cfg(not(windows))".dependencies.libc]
+version = "0.2.26"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index a6e9434..a6cbbd2 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,17 +1,17 @@
 [package]
 
 name = "num_cpus"
-version = "1.13.0" # don't forget to update html_root_url
+version = "1.13.1"
 description = "Get the number of CPUs on a machine."
 authors = ["Sean McArthur <sean@seanmonstar.com>"]
-license = "MIT/Apache-2.0"
+license = "MIT OR Apache-2.0"
 repository = "https://github.com/seanmonstar/num_cpus"
 documentation = "https://docs.rs/num_cpus"
 keywords = ["cpu", "cpus", "cores"]
 categories = ["hardware-support"]
 readme = "README.md"
 
-[dependencies]
+[target.'cfg(not(windows))'.dependencies]
 libc = "0.2.26"
 
 [target.'cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), target_os = "hermit"))'.dependencies]
diff --git a/METADATA b/METADATA
index 0b69247..f0d949f 100644
--- a/METADATA
+++ b/METADATA
@@ -1,7 +1,5 @@
 name: "num_cpus"
-description:
-    "Get the number of CPUs on a machine."
-
+description: "Get the number of CPUs on a machine."
 third_party {
   url {
     type: HOMEPAGE
@@ -9,9 +7,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/num_cpus/num_cpus-1.13.0.crate"
+    value: "https://static.crates.io/crates/num_cpus/num_cpus-1.13.1.crate"
   }
-  version: "1.13.0"
-  last_upgrade_date { year: 2020 month: 10 day: 15 }
+  version: "1.13.1"
   license_type: NOTICE
+  last_upgrade_date {
+    year: 2022
+    month: 3
+    day: 1
+  }
 }
diff --git a/README.md b/README.md
index a0bbe97..1de7d8e 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 # num_cpus
 
-[![crates.io](http://meritbadge.herokuapp.com/num_cpus)](https://crates.io/crates/num_cpus)
+[![crates.io](https://img.shields.io/crates/v/num_cpus.svg)](https://crates.io/crates/num_cpus)
 [![Travis CI Status](https://travis-ci.org/seanmonstar/num_cpus.svg?branch=master)](https://travis-ci.org/seanmonstar/num_cpus)
 [![AppVeyor status](https://ci.appveyor.com/api/projects/status/qn8t6grhko5jwno6?svg=true)](https://ci.appveyor.com/project/seanmonstar/num-cpus)
 
diff --git a/ci/cgroups/Dockerfile b/ci/cgroups/Dockerfile
index d5f288a..7636a47 100644
--- a/ci/cgroups/Dockerfile
+++ b/ci/cgroups/Dockerfile
@@ -1,4 +1,4 @@
-FROM rust:1.40
+FROM rust:latest
 
 WORKDIR /usr/num_cpus
 
diff --git a/fixtures/cgroups/proc/cgroups/mountinfo_multi_opt b/fixtures/cgroups/proc/cgroups/mountinfo_multi_opt
new file mode 100644
index 0000000..e03a95b
--- /dev/null
+++ b/fixtures/cgroups/proc/cgroups/mountinfo_multi_opt
@@ -0,0 +1,8 @@
+1 0 8:1 / / rw,noatime shared:1 - ext4 /dev/sda1 rw,errors=remount-ro,data=reordered
+2 1 0:1 / /dev rw,relatime shared:2 - devtmpfs udev rw,size=10240k,nr_inodes=16487629,mode=755
+3 1 0:2 / /proc rw,nosuid,nodev,noexec,relatime shared:3 - proc proc rw
+4 1 0:3 / /sys rw,nosuid,nodev,noexec,relatime shared:4 - sysfs sysfs rw
+5 4 0:4 / /sys/fs/cgroup ro,nosuid,nodev,noexec shared:5 - tmpfs tmpfs ro,mode=755
+6 5 0:5 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:6 - cgroup cgroup rw,cpuset
+7 5 0:6 / /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:7 shared:8 shared:9 - cgroup cgroup rw,cpu,cpuacct
+8 5 0:7 / /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime shared:8 - cgroup cgroup rw,memory
diff --git a/fixtures/cgroups/proc/cgroups/mountinfo_zero_opt b/fixtures/cgroups/proc/cgroups/mountinfo_zero_opt
new file mode 100644
index 0000000..ad27a96
--- /dev/null
+++ b/fixtures/cgroups/proc/cgroups/mountinfo_zero_opt
@@ -0,0 +1,8 @@
+1 0 8:1 / / rw,noatime shared:1 - ext4 /dev/sda1 rw,errors=remount-ro,data=reordered
+2 1 0:1 / /dev rw,relatime shared:2 - devtmpfs udev rw,size=10240k,nr_inodes=16487629,mode=755
+3 1 0:2 / /proc rw,nosuid,nodev,noexec,relatime shared:3 - proc proc rw
+4 1 0:3 / /sys rw,nosuid,nodev,noexec,relatime shared:4 - sysfs sysfs rw
+5 4 0:4 / /sys/fs/cgroup ro,nosuid,nodev,noexec shared:5 - tmpfs tmpfs ro,mode=755
+6 5 0:5 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:6 - cgroup cgroup rw,cpuset
+7 5 0:6 / /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime - cgroup cgroup rw,cpu,cpuacct
+8 5 0:7 / /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime shared:8 - cgroup cgroup rw,memory
diff --git a/src/lib.rs b/src/lib.rs
index 6c8280f..20474af 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -28,7 +28,6 @@
 //! [`rayon::ThreadPool`]: https://docs.rs/rayon/1.*/rayon/struct.ThreadPool.html
 #![cfg_attr(test, deny(warnings))]
 #![deny(missing_docs)]
-#![doc(html_root_url = "https://docs.rs/num_cpus/1.13.0")]
 #![allow(non_snake_case)]
 
 #[cfg(not(windows))]
@@ -47,6 +46,8 @@
 /// This function will get the number of logical cores. Sometimes this is different from the number
 /// of physical cores (See [Simultaneous multithreading on Wikipedia][smt]).
 ///
+/// This will always return at least `1`.
+///
 /// # Examples
 ///
 /// ```
@@ -75,6 +76,8 @@
 
 /// Returns the number of physical cores of the current system.
 ///
+/// This will always return at least `1`.
+///
 /// # Note
 ///
 /// Physical count is supported only on Linux, mac OS and Windows platforms.
diff --git a/src/linux.rs b/src/linux.rs
index 671a943..36f4727 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -18,7 +18,7 @@
 }
 
 macro_rules! some {
-    ($e:expr) => ({
+    ($e:expr) => {{
         match $e {
             Some(v) => v,
             None => {
@@ -26,7 +26,7 @@
                 return None;
             }
         }
-    })
+    }};
 }
 
 pub fn get_num_cpus() -> usize {
@@ -126,18 +126,15 @@
     // Should only be called once
     debug_assert!(CGROUPS_CPUS.load(Ordering::SeqCst) == 0);
 
-    match load_cgroups("/proc/self/cgroup", "/proc/self/mountinfo") {
-        Some(quota) => {
-            if quota == 0 {
-                return;
-            }
-
-            let logical = logical_cpus();
-            let count = ::std::cmp::min(quota, logical);
-
-            CGROUPS_CPUS.store(count, Ordering::SeqCst);
+    if let Some(quota) = load_cgroups("/proc/self/cgroup", "/proc/self/mountinfo") {
+        if quota == 0 {
+            return;
         }
-        None => return,
+
+        let logical = logical_cpus();
+        let count = ::std::cmp::min(quota, logical);
+
+        CGROUPS_CPUS.store(count, Ordering::SeqCst);
     }
 }
 
@@ -167,18 +164,14 @@
 
 impl Cgroup {
     fn new(dir: PathBuf) -> Cgroup {
-        Cgroup {
-            base: dir,
-        }
+        Cgroup { base: dir }
     }
 
     fn translate(mntinfo: MountInfo, subsys: Subsys) -> Option<Cgroup> {
         // Translate the subsystem directory via the host paths.
         debug!(
             "subsys = {:?}; root = {:?}; mount_point = {:?}",
-            subsys.base,
-            mntinfo.root,
-            mntinfo.mount_point
+            subsys.base, mntinfo.root, mntinfo.mount_point
         );
 
         let rel_from_root = some!(Path::new(&subsys.base).strip_prefix(&mntinfo.root).ok());
@@ -238,13 +231,27 @@
     fn parse_line(line: String) -> Option<MountInfo> {
         let mut fields = line.split(' ');
 
+        // 7 5 0:6 </> /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:7 - cgroup cgroup rw,cpu,cpuacct
         let mnt_root = some!(fields.nth(3));
-        let mnt_point = some!(fields.nth(0));
+        // 7 5 0:6 / </sys/fs/cgroup/cpu,cpuacct> rw,nosuid,nodev,noexec,relatime shared:7 - cgroup cgroup rw,cpu,cpuacct
+        let mnt_point = some!(fields.next());
 
-        if fields.nth(3) != Some("cgroup") {
+        // Ignore all fields until the separator(-).
+        // Note: there could be zero or more optional fields before hyphen.
+        // See: https://man7.org/linux/man-pages/man5/proc.5.html
+        // 7 5 0:6 / /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:7 <-> cgroup cgroup rw,cpu,cpuacct
+        // Note: we cannot use `?` here because we need to support Rust 1.13.
+        match fields.find(|&s| s == "-") {
+            Some(_) => {}
+            None => return None,
+        };
+
+        // 7 5 0:6 / /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:7 - <cgroup> cgroup rw,cpu,cpuacct
+        if fields.next() != Some("cgroup") {
             return None;
         }
 
+        // 7 5 0:6 / /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:7 - cgroup cgroup <rw,cpu,cpuacct>
         let super_opts = some!(fields.nth(1));
 
         // We only care about the 'cpu' option
@@ -281,16 +288,18 @@
             return None;
         }
 
-        fields.next().map(|path| Subsys { base: path.to_owned() })
+        fields.next().map(|path| Subsys {
+            base: path.to_owned(),
+        })
     }
 }
 
 #[cfg(test)]
 mod tests {
-    use std::path::{Path, PathBuf};
     use super::{Cgroup, MountInfo, Subsys};
+    use std::path::{Path, PathBuf};
 
-
+    // `static_in_const` feature is not stable in Rust 1.13.
     static FIXTURES_PROC: &'static str = "fixtures/cgroups/proc/cgroups";
 
     static FIXTURES_CGROUPS: &'static str = "fixtures/cgroups/cgroups";
@@ -304,12 +313,29 @@
 
     #[test]
     fn test_load_mountinfo() {
+        // test only one optional fields
         let path = join!(FIXTURES_PROC, "mountinfo");
 
         let mnt_info = MountInfo::load_cpu(path).unwrap();
 
         assert_eq!(mnt_info.root, "/");
         assert_eq!(mnt_info.mount_point, "/sys/fs/cgroup/cpu,cpuacct");
+
+        // test zero optional field
+        let path = join!(FIXTURES_PROC, "mountinfo_zero_opt");
+
+        let mnt_info = MountInfo::load_cpu(path).unwrap();
+
+        assert_eq!(mnt_info.root, "/");
+        assert_eq!(mnt_info.mount_point, "/sys/fs/cgroup/cpu,cpuacct");
+
+        // test multi optional fields
+        let path = join!(FIXTURES_PROC, "mountinfo_multi_opt");
+
+        let mnt_info = MountInfo::load_cpu(path).unwrap();
+
+        assert_eq!(mnt_info.root, "/");
+        assert_eq!(mnt_info.mount_point, "/sys/fs/cgroup/cpu,cpuacct");
     }
 
     #[test]
@@ -324,12 +350,7 @@
     #[test]
     fn test_cgroup_mount() {
         let cases = &[
-            (
-                "/",
-                "/sys/fs/cgroup/cpu",
-                "/",
-                Some("/sys/fs/cgroup/cpu"),
-            ),
+            ("/", "/sys/fs/cgroup/cpu", "/", Some("/sys/fs/cgroup/cpu")),
             (
                 "/docker/01abcd",
                 "/sys/fs/cgroup/cpu",
@@ -348,27 +369,10 @@
                 "/docker/01abcd/large",
                 Some("/sys/fs/cgroup/cpu/large"),
             ),
-
             // fails
-
-            (
-                "/docker/01abcd",
-                "/sys/fs/cgroup/cpu",
-                "/",
-                None,
-            ),
-            (
-                "/docker/01abcd",
-                "/sys/fs/cgroup/cpu",
-                "/docker",
-                None,
-            ),
-            (
-                "/docker/01abcd",
-                "/sys/fs/cgroup/cpu",
-                "/elsewhere",
-                None,
-            ),
+            ("/docker/01abcd", "/sys/fs/cgroup/cpu", "/", None),
+            ("/docker/01abcd", "/sys/fs/cgroup/cpu", "/docker", None),
+            ("/docker/01abcd", "/sys/fs/cgroup/cpu", "/elsewhere", None),
             (
                 "/docker/01abcd",
                 "/sys/fs/cgroup/cpu",
@@ -387,7 +391,7 @@
             };
 
             let actual = Cgroup::translate(mnt_info, subsys).map(|c| c.base);
-            let expected = expected.map(|s| PathBuf::from(s));
+            let expected = expected.map(PathBuf::from);
             assert_eq!(actual, expected);
         }
     }