<commit_before>// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015-2016 Oslo and Akershus University College of Applied Sciences
// and <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <os>
#include <stdio.h>
#include <cassert>

#include <memdisk>

// Includes std::string internal_banana
#include "banana.ascii"

void Service::start()
{
  INFO("FAT16", "Running tests for FAT16");
  auto disk = fs::new_shared_memdisk();
  assert(disk);

  // verify that the size is indeed N sectors
  CHECKSERT(disk->dev().size() == 16500, "Disk size 16500 sectors");

  // which means that the disk can't be empty
  CHECKSERT(!disk->empty(), "Disk not empty");

  // auto-mount filesystem
  disk->mount(
  [disk] (fs::error_t err)
  {
    CHECKSERT(!err, "Filesystem auto-mounted");

    auto& fs = disk->fs();
    printf("\t\t%s filesystem\n", fs.name().c_str());

    auto list = fs.ls("/");
    CHECKSERT(!list.error, "List root directory");

    CHECKSERT(list.entries->size() == 1, "Exactly one ent in root dir");

    auto& e = list.entries->at(0);
    CHECKSERT(e.is_file(), "Ent is a file");
    CHECKSERT(e.name() == "banana.txt", "Ents name is 'banana.txt'");

  });
  // re-mount on VBR1
  disk->mount(disk->VBR1,
  [disk] (fs::error_t err)
  {
    CHECKSERT(!err, "Filesystem mounted on VBR1");

    // verify that we can read file
    auto& fs = disk->fs();
    auto ent = fs.stat("/banana.txt");
    CHECKSERT(ent.is_valid(), "Stat file in root dir");
    CHECKSERT(ent.is_file(), "Entity is file");
    CHECKSERT(!ent.is_dir(), "Entity is not directory");
    CHECKSERT(ent.name() == "banana.txt", "Name is 'banana.txt'");

    printf("%s\n", internal_banana.c_str());

    // try reading banana-file
    auto buf = fs.read(ent, 0, ent.size());
    auto banana = buf.to_string();

    CHECKSERT(banana == internal_banana, "Correct banana #1");

    bool test = true;

    for (size_t i = 0; i < internal_banana.size(); i++)
    {
      // read one byte at a time
      buf = fs.read(ent, i, 1);<commit_msg>test: fat16  also update re-mount to use MBR<commit_after>// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015-2016 Oslo and Akershus University College of Applied Sciences
// and <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <os>
#include <stdio.h>
#include <cassert>

#include <memdisk>

// Includes std::string internal_banana
#include "banana.ascii"

void Service::start()
{
  INFO("FAT16", "Running tests for FAT16");
  auto disk = fs::new_shared_memdisk();
  assert(disk);

  // verify that the size is indeed N sectors
  CHECKSERT(disk->dev().size() == 16500, "Disk size 16500 sectors");

  // which means that the disk can't be empty
  CHECKSERT(!disk->empty(), "Disk not empty");

  // auto-mount filesystem
  disk->mount(
  [disk] (fs::error_t err)
  {
    CHECKSERT(!err, "Filesystem auto-mounted");

    auto& fs = disk->fs();
    printf("\t\t%s filesystem\n", fs.name().c_str());

    auto list = fs.ls("/");
    CHECKSERT(!list.error, "List root directory");

    CHECKSERT(list.entries->size() == 1, "Exactly one ent in root dir");

    auto& e = list.entries->at(0);
    CHECKSERT(e.is_file(), "Ent is a file");
    CHECKSERT(e.name() == "banana.txt", "Ents name is 'banana.txt'");

  });
  // re-mount on MBR (sigh)
  disk->mount(disk->MBR,
  [disk] (fs::error_t err)
  {
    CHECKSERT(!err, "Filesystem mounted on VBR1");

    // verify that we can read file
    auto& fs = disk->fs();
    auto ent = fs.stat("/banana.txt");
    CHECKSERT(ent.is_valid(), "Stat file in root dir");
    CHECKSERT(ent.is_file(), "Entity is file");
    CHECKSERT(!ent.is_dir(), "Entity is not directory");
    CHECKSERT(ent.name() == "banana.txt", "Name is 'banana.txt'");

    printf("%s\n", internal_banana.c_str());

    // try reading banana-file
    auto buf = fs.read(ent, 0, ent.size());
    auto banana = buf.to_string();

    CHECKSERT(banana == internal_banana, "Correct banana #1");

    bool test = true;

    for (size_t i = 0; i < internal_banana.size(); i++)
    {
      // read one byte at a time
      buf = fs.read(ent, i, 1);
{'fraction_non_alphanumeric': 0.15360864531069085, 'fraction_numerical': 0.013508297954457738, 'mean_word_length': 3.2941176470588234, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4634269', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1661, 'n_words': 561}